views:

734

answers:

1

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);

A: 

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 ...

}

...

Boon