Personal tools

MovieClipBody.as

From Whirled

(Redirected from Movieclips)
Jump to: navigation, search

MovieClipBody.as is a newer method of handling animations using movieclips in Flash. The older method uses Body.as and scenes in Flash.

Items such as configurable avatars require the use of MovieClipBody.as.


This article is a stub. You can help the wiki by expanding it.

Contents

Using MovieClipBody.as

A MovieClipBody.as avatar will have the same main scene code as the advanced avatar (Flash tutorial), but you will need to replace any mention of Body with MovieClipBody.

  1. Select the scene "main". If this is a new file, double-click "Scene 1" to rename it "main".
  2. Open the Actions window (F9).
  3. Paste in this code:

import flash.events.Event;
import com.whirled.AvatarControl;
 
if (_ctrl == null) {
_ctrl = new AvatarControl(this);
_body = new MovieClipBody(_ctrl, this, w);
_ctrl.addEventListener(Event.UNLOAD, handleUnload);
function handleUnload (... ignored) :void {
_body.shutdown();
}
}
 
var _ctrl :AvatarControl;
var _body :MovieClipBody;
4. Replace w with the width of your scene.

Making New States and Actions

Making a new movieClip in Adobe Flash CS3.
Making a new movieClip in Adobe Flash CS3.
  1. Make a movieClip that contains all the animation you want for that state/action/transition/incidental.
  2. Name the movieClip following the scene naming conventions from the Body.as tutorial linked above. This is not the instance name, it is the Class name. For example you could have movieclips named state_Default, state_Default_walking, action_Laugh, Default_to_Dancing, and state_Default_01:95.
  3. For each of your movieClips, you will need to "Export for ActionScript." Right click the movieClip name, select Properties → Advanced → Export For ActionScript → OK → OK. This allows the code in MovieClipBody.as to access the state/action/transition/incidental.
  4. Repeat steps 1-3 for each new state/action/transition/incidental.

Making State Triggered States/Actions

To make a state triggered state, your code would look something like this:

_ctrl.addEventListener(ControlEvent.STATE_CHANGED, stateChanged);
 
function stateChanged(e:ControlEvent) : void {
    var stateName:String = e.name // This is the state they changed to
    switch(stateName) {
        case "Egg":
            _ctrl.registerStates("Hatched");
            break;
        case "Hatched":
            _ctrl.registerStates("Adult", "Foghorn Leghorn");
            break;
        case "Adult":
        case "Foghorn Leghorn":
            _ctrl.registerStates("Egg");
            break;
    }
}

To make a state triggered action, the code would be similar, but there would be an _ctrl.registerActions("some actions"); call in there before the break statement.

See Also