简体   繁体   中英

Flex: Draw on different frames of a MovieClip

How can I used ActionScript to draw on different frames of a movie clip. That is, make it so that movieClip.gotoAndStop(0); will show something different to movieClip.gotoAndStop(1);

You can use addFrameScript in your code.

For example, let's say you have a movieclip associated with the class CustomMovieClip.

In your CustomMovieClip's constructor, you can write something like the following (untested code):

class CustomMovieClip {

...

function CustomMovieClip() { stop();

// add drawGraphicsForFrame1 code into frame 0

addFrameScript(0, drawGraphicsForFrame1);

// add drawGraphicsForFrame2 code into frame 1

addFrameScript(1, drawGraphicsForFrame2); ...

}

private function drawGraphicsForFrame1():void { stop();

var sprite:Sprite = new Sprite(); addChildAt(sprite, 1);

// draw in sprite

sprite.graphics.lineStyle ...

}

private function drawGraphicsForFrame2():void {

// remove the previous sprite (assumption: it's always at layer 1)

if (getChildAt(1) != null)
  removeChildAt(1);

 // draw new sprite

 var sprite:Sprite = new Sprite();
 addChildAt(sprite, 1);

 sprite.graphics.lineStyle ...

}

...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM