Skip to main content
December 15, 2011
Question

Copy as Motion in AS3 vs Copy Motion as XML

  • December 15, 2011
  • 1 reply
  • 714 views

Several day ago I posted a request for help regarding a problem I encountered using the CS5 Copy as Motion.

One of my problems was solved by placing a Copy Motion as XML in the Movie Clip timeline and using the addChild() to place it on the stage. Works great and I understand the parent child relationships a bit more clearly.

The Motion_End sets up a function to remove it from the stage.This works as well.

I am curious as to how I might take this XML code out of the MovieClip and place it in the timeline action script and write the code so it dynamically attaches it to the MovieClip when it is added to the stage.

I have tried numerous approaches but I'm not seeing a solution at this point:

Here is the basic code in the Movie Clip timeline(this is placed on to the the stage using addChild():

import fl.motion.Animator;

import fl.motion.MotionEvent;

var monster_xml:XML = <Motion duration="30" xmlns="fl.motion.*" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*">

    <source>

        <Source frameRate="24" x="268" y="160" scaleX="1" scaleY="1" rotation="0" elementType="movie clip" instanceName="monster" symbolName="monster_MC" class="Monster">

            <dimensions>

                <geom:Rectangle left="0" top="0" width="40" height="40"/>

            </dimensions>

            <transformationPoint>

                <geom:Point x="0.5" y="0.5"/>

            </transformationPoint>

        </Source>

    </source>

    <Keyframe index="0" tweenSnap="true">

        <tweens>

            <SimpleEase ease="0"/>

        </tweens>

    </Keyframe>

    <Keyframe index="29" scaleX="2.5" scaleY="2.5"/>

</Motion>

var this_animator:Animator = new Animator(monster_xml, this);

this_animator.play();

this_animator.addEventListener(MotionEvent.MOTION_END, hurtPlayer);

                              

                               function hurtPlayer(evt:MotionEvent):void

                               {

                                   this.parent.removeChild(this);

                               }

Here is the code placed into the first frame of the timeline(can you target the MovieClip?):

import flash.display.MovieClip;

import flash.events.MouseEvent;

import fl.motion.MotionEvent;

import fl.motion.Animator;

import fl.motion.MotionEvent;

var cursor:MovieClip;

var monster:MovieClip = new Monster;

monster.x = 150;

monster.y = 150;

addChild(monster);

function initializeGame():void

{

    cursor = new Cursor();

    addChild(cursor);

    cursor.enabled = false;

    Mouse.hide();

    stage.addEventListener(MouseEvent.MOUSE_MOVE, dragCursor);

}

function dragCursor(evt:MouseEvent):void

{

    cursor.x = this.mouseX;

    cursor.y = this.mouseY;

}

var monster_xml:XML = <Motion duration="30" xmlns="fl.motion.*" xmlns:geom="flash.geom.*" xmlns:filters="flash.filters.*">

    <source>

        <Source frameRate="24" x="268" y="160" scaleX="1" scaleY="1" rotation="0" elementType="movie clip" instanceName="monster" symbolName="monster_MC" class="Monster">

            <dimensions>

                <geom:Rectangle left="0" top="0" width="40" height="40"/>

            </dimensions>

            <transformationPoint>

                <geom:Point x="0.5" y="0.5"/>

            </transformationPoint>

        </Source>

    </source>

    <Keyframe index="0" tweenSnap="true">

        <tweens>

            <SimpleEase ease="0"/>

        </tweens>

    </Keyframe>

    <Keyframe index="29" scaleX="2.5" scaleY="2.5"/>

</Motion>

var this_animator:Animator = new Animator(monster_xml, this);

this_animator.play();

this_animator.addEventListener(MotionEvent.MOTION_END, hurtPlayer);

                              

                               function hurtPlayer(evt:MotionEvent):void

                               {

                                   this.parent.removeChild(this);

                               }

This topic has been closed for replies.

1 reply

Kenneth Kawamoto
Community Expert
Community Expert
December 16, 2011

If you want to animate "monster" then it should be:

new Animator(monster_xml, monster);

--

Kenneth Kawamoto

http://www.materiaprima.co.uk/