开发者

How do I change subclass' variable from superclass?

For some time now I have been making a very easy game for iPhone in flash using as3. Recently I came in contact with a small problem, which is why I am posting this!

The problem: I have a superclass from which开发者_如何学运维 everything derives. In the superclass I initiate and place an Object on stage.

 1. var myObject:typeA = new typeA();
 2. stage.addChild(myObject);

As you can see this object follows the class 'typeA' which, ocf, has its own actionscript file. Inside of this file I have declared a global variable of type string.

What I want to do is change the varbiable on the new object from the superclass. Therefor I tried as following:

 1. myObject.myVariable = 'someSortOfString';

Unfortunatly it didn't work and so I wonder how to do this; change a subclass' variable from the superclass.


You need to declare the variable that is being accessed from the subclass as protected (Or public), by default the variable is private so only accesible by the superclass.

e.g. protected var myObject:typeA = new typeA();

BTW did you mean change the superclass variable from the subclass instead of "change the subclass variable from the superclass"?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜