开发者

Changing movieclips in FlashDevelop (or other IDEs with no graphics)

I am doing this:

    [Embed(source = "../lib/hfront.swf")]
    private var charfront1Class : Class;
    private var charfront1:MovieClip = new charfront1Class;

in order to create a movieclip object in FlashDevelop. Because there is no option (like in CS5) to give a library object a class inherently.

What I need to do is be able to switch which movie clip is being displayed as my character walks about. Do I have to create a separate class for each movieclip and call them in and out of visibility?? Or is there a better way, a way to "switch" which movie clip my current clas开发者_运维问答s is pointing to?

Thanks


Firstly the embed isn't correct. If you embed an entire SWF like that you won't be able to control its timeline.

To have a MovieClip that you can manipulate you must embed a symbol of this SWF:

[Embed(source = "../lib/hfront.swf", symbol="walk")]
private var walkClass : Class;
private var walk:MovieClip = new walkClass;

[Embed(source = "../lib/hfront.swf", symbol="run")]
private var runClass : Class;
private var run:MovieClip = new runClass;

Secondly, make sure you actually call stop() for each animation or they will run (and consume CPU) even if they are off the display list.

Finally here's a (naive) example of showing the 2 embedded anims (as children of a class extending Sprite):

// current anim
private var current:MovieClip;

// showAnim("run") or showAnim("walk")
public function showAnim(anim:String):void {
    if (current) { current.stop(); removeChild(current); }
    current = this[anim];
    addChild(current);
    current.gotoAndPlay(1);
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜