PDA

View Full Version : Access properties of getChildAt


Knorcedger
05-04-2007, 07:09 AM
I was using Flash 9 AS3 Preview and i was using getChildAt to access the properties of an Object, but im testing it on Flex Builder 2, and it doesnt work. You can see the code on the example that follows. What can i do? Why isnt it tracing the "t" property when i use the getChildAt? Is there something else i can use?


package {
import flash.display.Sprite;

public class test extends Sprite
{
public var t:int

public function test()
{
t = 7
fire()
}

private function fire():void
{
trace(this.t) // traces -> 7
trace(stage.getChildAt(0)) // traces -> [object test]
//trace(stage.getChildAt(0).t) // Undefined property t
}
}
}

Dazzer
05-04-2007, 07:21 AM
probably because the stage on Flash is totally different for the stage of Flex. That's my guess.

senocular
05-04-2007, 10:36 AM
possibly because of this?
http://board.flashkit.com/board/forumdisplay.php?f=102

(weird that I saw this same question 3 times in the past 10 minutes)

therealconekt
10-09-2007, 09:10 AM
possibly because of this?
http://board.flashkit.com/board/forumdisplay.php?f=102

(weird that I saw this same question 3 times in the past 10 minutes)

For those of you who can't find the post he's referring to, here's the problem:

When you call call getChildAt, etc on something it returns an object of type "DisplayObject" which doesn't have the property you're trying to access.

For example:
getChildAt(0).myPropIn order to access your property you need to cast the returned object as the class of the instance you're trying to refer to.

MyClass(getChildAt(0)).myPropThen you should be just dandy.