|
-
Flash Incompetent
[CS3] addChild problems...
I have this code:
Code:
private function loadSections () {
//create top right section
topRight = new MovieClip();
topRight.x = 250 - (6 * ts);
topRight.y = 2 * ts;
myBuildParent.addChild(topRight);
var txtOption:Array = new Array();
//create the 5 text options
for (var i:int=1; i<6; i++) {
txtOption[i] = new TextField();
txtOption[i].text = "Option" + i;
txtOption[i].x = 2 * ts;
txtOption[i].y = i * ts;
topRight.addChild(txtOption[i]);
}
defineOption(1, "Buy", 101);
}
private function defineOption (optNum:int, txt:String, type:int):void {
//this is what doesnt work =(
//causes TypeError: Error #1010: A term is undefined and has no properties.
myBuildParent.topRight.txtOption[optNum].text = txt;
trace(myBuildParent); //returns: [object MovieClip]
trace(myBuildParent.topRight); //returns: undefined
}
I can't seem to define text for txtOption[#] which is a child of topRight which is a child of myBuildParent... I have this feeling its a really simple answer but I've spent the last two hours trying to figure it out...
anyways, thanks in advance for any help you can give,
ChaseNYC
-
5+5=55
I think it's because you're declaring "var txtOption:Array = new Array();" inside the function, so it isn't available anywhere else (like in the defineOption function). Try declaring txtOption outside the function, and let me know if that fixes it.
Also, you might not be able to access topRight using the dot (.) operator like this, in fact I'm pretty sure you can't. You have to use getChildAt, or getChildByName or something similar instead.
Try:
topRight = new MovieClip();
topRight.name = "topRight";
...
myBuildParent.getChildByName("topRight").txtOption[optNum].text = txt;
Edit again:
This still won't work, since txtOption is not a property of topRight... so add a line above like:
var txtOption:Array = new Array();
topRight.txtOption = txtOption;
Hope this helps.
Last edited by Schfifty Five; 07-04-2008 at 02:06 AM.
-
Flash Incompetent
I tried that but it didn't work, I'm pretty sure it has something to do with topRight not getting recognized in the myBuildParent.topRight.txtOption[optNum].text = txt;
-
5+5=55
 Originally Posted by ChaseNYC
I tried that but it didn't work, I'm pretty sure it has something to do with topRight not getting recognized in the myBuildParent.topRight.txtOption[optNum].text = txt;
Try what I edited in
-
Senior Member
topRight = new MovieClip();
topRight.name = "topRight";
var txtOption:Array = new Array();
topRight.txtOption = txtOption;
//convert display object to movie clip
MovieClip(this.getChildByName("topRight")).txtOpti on[optNum].text = txt;
-
Flash Incompetent
great tonypa, that works wonders! [resolved!]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|