开发者

How to use addchild in another class not the main class as of .fla file?

i want to add to stage a movieclip in another class not the .as file as the same name of .fla file how can i get this.

开发者_如何学Go

When i run same code in main.as i get the result but in another class it runs but no result.


First add the other class to the stage using an addChild from the document class (main class). Now just call this.addChild(whatever) from the other class - it will work.

Adding the new child to self

Stage
|
|__DocumentClass - this.addChild(another_class)
   |
   | 
   |
   |__AnotherClass - this.addChild(new movieclip)
      |
      | 
      |
      |__ NewMovieClip      

Adding the new child to the main movieclip

Stage
|
|__DocumentClass - this.addChild(another_class)
   |
   | 
   |
   |__AnotherClass - this.root.addChild(new movieclip)
   |
   | 
   |
   |__ NewMovieClip      

Adding the new child to the stage

Stage
|
|__DocumentClass - this.addChild(another_class)
|  |
|  | 
|  |
|  |__AnotherClass - this.stage.addChild(new movieclip)
|
| 
|
|__ NewMovieClip 


Either you need to pass Stage object to the other class or make this other class a DisplayObject and add it to the Stage then stage object will be accessible to this class and you can add new DisplayObject to the stage.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜