lundi 29 février 2016

loading image from xml issue as3

I have created a Flash CC Professional file that loads XML data that includes links, multiple text sections and an image link. as users progress though the program and text, the corresponding image should load into a mc named imgholder. I have traced the var 'img' from the xml file to the incremental image loader but still can't figure out why the image isn't loading into the container. ...oh and it isn't throwing any errors.

HELP!! thanks in advance!

Frame 1 AS3:

    var questions:Array=new Array();
var answers:Array=new Array();
var numb:Array=new Array();
var rtext:Array=new Array();
var img:Array = new Array();



//XML loader
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, loadXML);
loader.load(new URLRequest("UT_quiz.xml"));
function loadXML(e:Event):void
{
        var myxml = new XML(e.target.data);
        var loop =myxml.ques.length();
                for (var i=0;i<loop;i++){
                    questions[i]=myxml.ques[i].q1;
                    numb[i]=myxml.ques[i].qnum;
                    answers[i]=[myxml.ques[i].op1,myxml.ques[i].op2,myxml.ques[i].op3,myxml.ques[i].op4];
                    rtext[i]=myxml.ques[i].riddle;
                    img[i]=myxml.ques[i].image;


                }//loop
                gotoAndPlay(2);

}
stop();

Frame 2 AS3:

import flash.text.TextField;
import flash.utils.getTimer;
import flash.events.Event;

var qno=0; var rnd1;

function change_question(){
                tick.visible=false;cross.visible=false;
                rnd1=Math.ceil(Math.random()*4);
                q.text=questions[qno];
                qnum.text=numb[qno];
                rtxt.text=rtext[qno];
                imgholder.MovieClip=img[qno];
                if(rnd1==1){opt1.text=answers[qno][0];opt2.text=answers[qno][1];opt3.text=answers[qno][2];opt4.text=answers[qno][3];}
                if(rnd1==2){opt1.text=answers[qno][3];opt2.text=answers[qno][0];opt3.text=answers[qno][1];opt4.text=answers[qno][2];}
                if(rnd1==3){opt1.text=answers[qno][2];opt2.text=answers[qno][3];opt3.text=answers[qno][0];opt4.text=answers[qno][1];} 
                if(rnd1==4){opt1.text=answers[qno][1];opt2.text=answers[qno][2];opt3.text=answers[qno][3];opt4.text=answers[qno][0];}
                }//function change_question

function enable_disable(a){
    if(a==0){shade1.mouseEnabled=false;shade2.mouseEnabled=false;shade3.mouseEnabled=false;shade4.mouseEnabled=false;}
    if(a==1){shade1.mouseEnabled=true;shade2.mouseEnabled=true;shade3.mouseEnabled=true;shade4.mouseEnabled=true;}} 

change_question();


next_b.addEventListener(MouseEvent.CLICK, ButtonAction1);
function ButtonAction1(eventObject:MouseEvent) {

        qno++;change_question();

if(MovieClip(root).currentGalleryItem == 4){
            MovieClip(root).currentGalleryItem--;
            MovieClip(root).slideRight();
        }   
    }

shade1.addEventListener(MouseEvent.CLICK, ButtonAction2);
shade2.addEventListener(MouseEvent.CLICK, ButtonAction3);
shade3.addEventListener(MouseEvent.CLICK, ButtonAction4);
shade4.addEventListener(MouseEvent.CLICK, ButtonAction5);

function ButtonAction2(eventObject:MouseEvent) {if(rnd1==1){tick.visible=true;tick.y=shade1.y;tick.x=shade1.x; score+=50; scorecounter.text = score.toString();}else{cross.visible=true;cross.y=shade1.y;cross.x=shade1.x; score-=25; scorecounter.text = score.toString();}}
function ButtonAction3(eventObject:MouseEvent) {if(rnd1==2){tick.visible=true;tick.y=shade2.y;tick.x=shade2.x; score+=50; scorecounter.text = score.toString();}else{cross.visible=true;cross.y=shade2.y;cross.x=shade2.x; score-=25; scorecounter.text = score.toString();}}
function ButtonAction4(eventObject:MouseEvent) {if(rnd1==3){tick.visible=true;tick.y=shade3.y;tick.x=shade3.x; score+=50; scorecounter.text = score.toString();}else{cross.visible=true;cross.y=shade3.y;cross.x=shade3.x; score-=25; scorecounter.text = score.toString();}}
function ButtonAction5(eventObject:MouseEvent) {if(rnd1==4){tick.visible=true;tick.y=shade4.y;tick.x=shade4.x; score+=50; scorecounter.text = score.toString();}else{cross.visible=true;cross.y=shade4.y;cross.x=shade4.x; score-=25; scorecounter.text = score.toString();}}



var score:Number = 0;

function init():void {
    if (score < 0) {
        score == 0;
    }
    scorecounter.text = score.toString();
}


/*var gameStartTime:uint;
var gameTime:uint;

function currTime(e:Event) {
    gameStartTime = getTimer();
    gameTime = 0;
}

addEventListener(event.ENTER_FRAME,showTime);

function showTime(e:Event) {
    gameTime = getTimer()-gameStartTime;
    gameTimeField.text = "Time: "+gameTime;
}*/

init();

stop();

Aucun commentaire:

Enregistrer un commentaire