AS3 Accessing Variables of Parent Class From Child
Posted
by TheDarkIn1978
on Stack Overflow
See other posts from Stack Overflow
or by TheDarkIn1978
Published on 2010-04-11T23:09:23Z
Indexed on
2010/04/11
23:13 UTC
Read the original article
Hit count: 241
i'm trying to assign a parent's variable from the parent's child
//Parent
public class Main extends Sprite
{
public var selectedSquare:Sprite;
public function Main()
{
//inits and adds new Square child class to display list
}
...
-------
//Child
public function dragSquare(evt:MouseEvent):void
{
Sprite(parent).selectedSquare = this; //evil doesn't work!
parent.addChild(this);
this.startDrag();
}
i'm receiving this error, but i'm casting parent from displayObjectContainer to a Sprite so i have no idea why it's not working.
1119: Access of possibly undefined property selectedSquare through a reference with static type flash.display:Sprite.
© Stack Overflow or respective owner