Skip to main content
Participating Frequently
August 19, 2011
Answered

Actionscript inside event handlers

  • August 19, 2011
  • 1 reply
  • 1699 views

hey guys. i copied the motion of a tween as actionscript and pasted it into the actions panel and it worked perfectly. I then took that code and nested it into some actionscript for a mouse click, such that when i click the mouse, the actionscript wud envoke....but nothing happens...

movieClip_1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler_1);

function fl_MouseClickHandler_1(event:MouseEvent):void

{

         //actionscript for movieclip2 to move

}

any reason why this may be doing this??

This topic has been closed for replies.
Correct answer markerline

i have no compile errors. the following is another animation with other functions, like fade ins and outs inside of a mouse over and nested mouse out event where everything works:

thanks for looking into this tho, really appreciate it

movieClip_12.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler_15);

function fl_MouseOverHandler_15(event:MouseEvent):void

{

movieClip_12.addEventListener(Event.ENTER_FRAME, fl_FadeSymbolIn_14);

movieClip_12.alpha = 0;

function fl_FadeSymbolIn_14(event:Event)

{

movieClip_12.alpha += 0.03;

if(movieClip_12.alpha >= 0.78)

{

movieClip_12.removeEventListener(Event.ENTER_FRAME, fl_FadeSymbolIn_14);

}

}

movieClip_18.addEventListener(Event.ENTER_FRAME, fl_FadeSymbolIn_22);

movieClip_18.alpha = 0;

function fl_FadeSymbolIn_22(event:Event)

{

movieClip_18.alpha += 0.03;

if(movieClip_18.alpha >= 0.78)

{

movieClip_18.removeEventListener(Event.ENTER_FRAME, fl_FadeSymbolIn_22);

}

}

import fl.motion.AnimatorFactory;

import fl.motion.MotionBase;

import fl.motion.Motion;

import flash.filters.*;

import flash.geom.Point;

var __motion_ziontext:MotionBase;

if(__motion_ziontext == null) {

    __motion_ziontext = new Motion();

    __motion_ziontext.duration = 24;

    __motion_ziontext.addPropertyArray("x", [0,0.124826,0.238826,0.342478,0.436261,0.520652,0.596174,0.663348,0.722609,0.774435,0.819391,0.857957,0.890565,0.917783,0.940043,0.957913,0.971783,0.982217,0.989696,0.994739,0.997739,0.999304,1,1]);

    __motion_ziontext.addPropertyArray("y", [0,-29.0845,-55.6465,-79.7974,-101.649,-121.312,-138.909,-154.56,-168.368,-180.443,-190.918,-199.904,-207.502,-213.843,-219.03,-223.194,-226.425,-228.857,-230.599,-231.774,-232.473,-232.838,-233,-233]);

    __motion_ziontext.addPropertyArray("scaleX", [1.000000]);

    __motion_ziontext.addPropertyArray("scaleY", [1.000000]);

    __motion_ziontext.addPropertyArray("skewX", [0]);

    __motion_ziontext.addPropertyArray("skewY", [0]);

    __motion_ziontext.addPropertyArray("rotationConcat", [0]);

    __motion_ziontext.addPropertyArray("blendMode", ["normal"]);

    __motion_ziontext.addPropertyArray("cacheAsBitmap", [false]);

    __motion_ziontext.addPropertyArray("alphaMultiplier", [0.000000,0.043478,0.086957,0.130435,0.173913,0.217391,0.260870,0.304348,0.317826,0.331304,0.364783,0.398261,0.421739,0.455217,0.488696,0.516438,0.545383,0.576372,0.603864,0.615437,0.647852,0.667231,0.682587,0.700000]);

    var __animFactory_ziontext:AnimatorFactory = new AnimatorFactory(__motion_ziontext);

    __animFactory_ziontext.transformationPoint = new Point(0.499654, 0.499318);

    __animFactory_ziontext.addTarget(ziontext, 1);

}

movieClip_16.addEventListener(Event.ENTER_FRAME, fl_FadeSymbolIn_18);

movieClip_16.alpha = 0;

function fl_FadeSymbolIn_18(event:Event)

{

movieClip_16.alpha += 0.1;

if(movieClip_16.alpha >= 1)

{

movieClip_16.removeEventListener(Event.ENTER_FRAME, fl_FadeSymbolIn_18);

}

}

movieClip_17.addEventListener(Event.ENTER_FRAME, fl_FadeSymbolIn_19);

movieClip_17.alpha = 0;

function fl_FadeSymbolIn_19(event:Event)

{

movieClip_17.alpha += 0.1;

if(movieClip_17.alpha >= 1)

{

movieClip_17.removeEventListener(Event.ENTER_FRAME, fl_FadeSymbolIn_19);

}

}

movieClip_12.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler_11);

function fl_MouseOutHandler_11(event:MouseEvent):void

{

movieClip_12.addEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut_11);

movieClip_12.alpha = 0.78;

function fl_FadeSymbolOut_11(event:Event)

{

movieClip_12.alpha -= 0.08;

if(movieClip_12.alpha <= 0)

{

movieClip_12.removeEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut_11);

}

}

movieClip_18.addEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut_18);

movieClip_18.alpha = 0.78;

function fl_FadeSymbolOut_18(event:Event)

{

movieClip_18.alpha -= 0.08;

if(movieClip_18.alpha <= 0)

{

movieClip_18.removeEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut_18);

}

}

import fl.motion.AnimatorFactory;

import fl.motion.MotionBase;

import fl.motion.Motion;

import flash.filters.*;

import flash.geom.Point;

var __motion_ziontext:MotionBase;

if(__motion_ziontext == null) {

    __motion_ziontext = new Motion();

    __motion_ziontext.duration = 24;

    __motion_ziontext.addPropertyArray("x", [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);

    __motion_ziontext.addPropertyArray("y", [0,0,0.151957,0.516652,1.21565,2.39078,4.13322,6.56452,9.79613,13.9597,19.1465,25.4882,33.086,42.0717,52.5466,64.622,78.4298,94.0813,111.678,131.341,153.192,177.343,203.905,233]);

    __motion_ziontext.addPropertyArray("scaleX", [1.000000]);

    __motion_ziontext.addPropertyArray("scaleY", [1.000000]);

    __motion_ziontext.addPropertyArray("skewX", [0]);

    __motion_ziontext.addPropertyArray("skewY", [0]);

    __motion_ziontext.addPropertyArray("rotationConcat", [0]);

    __motion_ziontext.addPropertyArray("blendMode", ["normal"]);

    __motion_ziontext.addPropertyArray("cacheAsBitmap", [false]);

    __motion_ziontext.addPropertyArray("alphaMultiplier", [.600000,0.556957,0.513913,0.480870,0.437826,0.394783,0.351739,0.308696,0.255652,0.202609,0.169565,0.126522,0.083478,0.060435,0.047391,0.024348,0.001304,0,0,0,0,0,0,0]);

    var __animFactory_ziontext:AnimatorFactory = new AnimatorFactory(__motion_ziontext);

    __animFactory_ziontext.transformationPoint = new Point(0.499654, 0.499318);

    __animFactory_ziontext.addTarget(ziontext, 1);

}

movieClip_16.addEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut_16);

movieClip_16.alpha = 1;

function fl_FadeSymbolOut_16(event:Event)

{

movieClip_16.alpha -= 0.03;

if(movieClip_16.alpha <= 0)

{

movieClip_16.removeEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut_16);

}

}

movieClip_17.addEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut_17);

movieClip_17.alpha = 1;

function fl_FadeSymbolOut_17(event:Event)

{

movieClip_17.alpha -= 0.03;

if(movieClip_17.alpha <= 0)

{

movieClip_17.removeEventListener(Event.ENTER_FRAME, fl_FadeSymbolOut_17);

}

}

}

}


I created a simple animation based on my research into the AnimatorFactory....

import fl.motion.AnimatorFactory;

import fl.motion.MotionBase;

import fl.motion.Motion;

import flash.filters.*;

import flash.geom.Point;

import flash.events.MouseEvent;

var __motion_myCircle_mc:MotionBase;

stop();

mySq_mc.addEventListener(MouseEvent.CLICK, mySqEvent);

if(__motion_myCircle_mc == null) {

    __motion_myCircle_mc = new Motion();

    __motion_myCircle_mc.duration = 15;

    // Call overrideTargetTransform to prevent the scale, skew,

    // or rotation values from being made relative to the target

    // object's original transform.

    // __motion_myCircle_mc.overrideTargetTransform();

    // The following calls to addPropertyArray assign data values

    // for each tweened property. There is one value in the Array

    // for every frame in the tween, or fewer if the last value

    // remains the same for the rest of the frames.

    __motion_myCircle_mc.addPropertyArray("x", [0,12.0679,24.1357,36.2036,48.2714,60.3393,72.4071,84.475,96.5429,108.611,120.679,132.746,144.814,156.882,168.95]);

    __motion_myCircle_mc.addPropertyArray("y", [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);

    __motion_myCircle_mc.addPropertyArray("scaleX", [1.000000]);

    __motion_myCircle_mc.addPropertyArray("scaleY", [1.000000]);

    __motion_myCircle_mc.addPropertyArray("skewX", [0]);

    __motion_myCircle_mc.addPropertyArray("skewY", [0]);

    __motion_myCircle_mc.addPropertyArray("rotationConcat", [0]);

    __motion_myCircle_mc.addPropertyArray("blendMode", ["normal"]);

    __motion_myCircle_mc.addPropertyArray("cacheAsBitmap", [false]);

    // Create an AnimatorFactory instance, which will manage

    // targets for its corresponding Motion.

    var __animFactory_myCircle_mc:AnimatorFactory = new AnimatorFactory(__motion_myCircle_mc);

    __animFactory_myCircle_mc.transformationPoint = new Point(0.500000, 0.500000);

    // Call the addTarget function on the AnimatorFactory

    // instance to target a DisplayObject with this Motion.

    // The second parameter is the number of times the animation

    // will play - the default value of 0 means it will loop.

     function mySqEvent(e:MouseEvent):void{

     __animFactory_myCircle_mc.addTarget(myCircle_mc, 0);

     }

}

The above works because of the structure of the __animFactory call at the bottom of the script.  Note that the mouseEvent function wraps this call and that the event listener is outside of the if statement near the top of the script....

1 reply

markerline
Inspiring
August 19, 2011

can you post more of your code, like the part that you commented out?

markerline
Inspiring
August 19, 2011

When you say you nested it, did you perhaps put the code inside of another function?  This would probably be the cause of it not working.  (if the code is a function nested in a function it won't work)

Message was edited by: markerline

wizard246Author
Participating Frequently
August 19, 2011

this is the full code..

movieClip_1.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler_3);

function fl_MouseOverHandler_3(event:MouseEvent):void

{

trace("Moused over");

import fl.motion.AnimatorFactory;

import fl.motion.MotionBase;

import fl.motion.Motion;

import flash.filters.*;

import flash.geom.Point;

var __motion_circle_3:MotionBase;

if(__motion_circle_3 == null) {

    __motion_circle_3 = new Motion();

    __motion_circle_3.duration = 75;

    __motion_circle_3.addPropertyArray("x", [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);

    __motion_circle_3.addPropertyArray("y", [0,0.20339,0.813559,1.83051,3.25781,5.09188,7.33274,9.98038,13.0384,16.4996,20.3711,24.6494,29.3381,34.43,39.9322,45.8412,52.157,58.8796,66.0089,73.5486,81.4951,89.8484,98.6084,107.779,117.352,127.336,137.727,148.525,159.732,171.347,183.365,195.793,208.632,221.873,235.504,249.581,264.05,243.661,225.674,210.084,196.892,186.098,177.702,171.707,168.111,166.908,168.111,171.707,177.702,186.098,196.892,210.084,225.674,243.661,264.05,253.128,244.196,237.245,232.282,229.306,228.314,229.306,232.282,237.245,244.196,253.128,264.05,258.298,254.187,251.725,250.901,251.725,254.187,258.298,264.05]);

    __motion_circle_3.addPropertyArray("scaleX", [1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.268397,1.301610,1.268367,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.177976,1.200000,1.177976,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.100000,1.000000]);

    __motion_circle_3.addPropertyArray("scaleY", [1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,0.633725,0.588400,0.633766,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,0.764314,0.735500,0.769149,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,1.000000,0.800000,1.000000]);

    __motion_circle_3.addPropertyArray("skewX", [0]);

    __motion_circle_3.addPropertyArray("skewY", [0]);

    __motion_circle_3.addPropertyArray("rotationConcat", [0]);

    __motion_circle_3.addPropertyArray("blendMode", ["normal"]);

    __motion_circle_3.addPropertyArray("cacheAsBitmap", [false]);

    var __animFactory_circle_3:AnimatorFactory = new AnimatorFactory(__motion_circle_3);

    __animFactory_circle_3.transformationPoint = new Point(0.500000, 0.995565);

   __animFactory_circle_3.addTarget(circle_3, 1);

}

}