开发者

How do I change subclass' variable from superclass?

开发者 https://www.devze.com 2023-02-02 12:09 出处:网络
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!

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

精彩评论

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

关注公众号