all groups > flash actionscript > november 2007 >
You're in the

flash actionscript

group:

dynamically put variables inside a movie clip


dynamically put variables inside a movie clip DJ James
11/2/2007 6:48:17 PM
flash actionscript:
In the past, I could dynamically add variables to a movie clip to assign values
to them so that I was able to read them later per movie clip.

It doesn't seem like I can do this now. Is there anyway to do it?

Also, this is in a class, and when the student has answerd the quesiton, I
need variables to be set from the main stage. (nextEnabled, backEnabled for
buttons to become active). So on a side note, from a class, how do I set
variables in the main stage?

thanks in advance

This is for a XML generated exam, and I'm creating the answers dynamically
here:


for(var i:uint=0; i<ansTot; i++) {
var arNum:uint = Number(listArray[i]);
var disMC:MovieClip = new MovieClip();

var ansText:TextField = new TextField();
disMC.addChild(ansText).name = "ansText";
ansText.x = 15;
if(i == 0) {
thisY = stemText.height + 20;
ansText.y = thisY;
} else {
ansText.y = thisY;
}
ansText.width = 969;
ansText.autoSize = TextFieldAutoSize.LEFT;
ansText.styleSheet = quesCSS;
ansText.wordWrap = true;
ansText.multiline = true;
ansText.selectable = false;
ansText.condenseWhite = true;
ansText.antiAliasType = "advanced";
//ansText.border = true;
ansText.borderColor = 0xFFFFFF;
ansText.htmlText = "<span class='n'>" + formatScreenText(subXML[arNum]) +
"</span>";

disMC.defaultText = formatScreenText(subXML[arNum]);
disMC.remediation = subXML[arNum].@remediation;
disMC.isCorrect = subXML[arNum].@correct;

disMC.addEventListener(MouseEvent.CLICK, answerClicked);

thisY += ansText.height + 10;

this.addChild(disMC);
}

private function answerClicked(event:Event):void {
var myAns = event.target;
if(this.isCorrect == "1") {
this.ansText.htmlText = "<span class='cor'>" + this.defaultText + "</span>";
} else {
this.ansText.htmlText = "<span class='wng'>" + this.defaultText + "</span>";
}
}
Re: dynamically put variables inside a movie clip kglad
11/2/2007 7:50:37 PM
1. you do it the same way in as3 as in as2. often the compiler needs help
knowing you're accessing a movieclip property and you need to type your object
as a movieclip.

2. you can dispatch a custom event from your class, based on something that
occurs within your class, to any class member that has a listener.
Re: dynamically put variables inside a movie clip DJ James
11/2/2007 7:54:38 PM
figured it out, just have to dig around to find it LOL:
event.target.parent.defaultText

but still not sure about how to set the nextButton variable to true when they
either get the answer correct, or fail on the second try.
AddThis Social Bookmark Button