Copy link to clipboard
Copied
So I have this motion script which I copied from Cs6 as "Copy Motion as AS3". It works fine until I tried to control it with a mouse event function. So what am I missing? it works fine outside the function but not at all inside.
import fl.motion.AnimatorFactory;
import fl.motion.MotionBase;
import fl.motion.Motion;
import flash.filters.*;
import flash.geom.Point;
var __motion_NewBall_7: MotionBase;
theButton.addEventListener(MouseEvent.CLICK, on_press1);
function on_press1(event: MouseEvent): void {
if (__motion_NewBall_7 == null) {
__motion_NewBall_7 = new Motion();
__motion_NewBall_7.duration = 60;
__motion_NewBall_7.addPropertyArray("x", [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4.02143, -8.04286, -12.0603, -16.0857, -20.1071, -24.1246, -28.15, -35.6987, -43.2474, -50.7885, -58.3447, -65.8934, -73.4346, -80.9832, -88.5395, -96.0882, -103.637, -111.186, -118.727, -126.283, -133.824, -141.38, -148.929, -156.478, -164.026, -171.575, -179.124, -186.672, -194.221, -201.77, -209.311, -216.867, -224.416, -231.957, -239.506, -247.062, -254.611, -262.152, -269.708, -277.257, -284.805, -292.346, -299.903, -307.451, -315]);
__motion_NewBall_7.addPropertyArray("y", [0, 9.41071, 18.8214, 28.2227, 37.6429, 47.0536, 56.4549, 65.875, 75.2857, 84.6964, 94.1071, 103.518, 112.919, 122.339, 131.75, 124.157, 116.564, 108.979, 101.379, 93.7857, 86.2004, 78.6, 84.0237, 89.4474, 94.8656, 100.295, 105.718, 111.137, 116.56, 121.989, 127.413, 132.837, 138.261, 143.679, 149.108, 154.526, 159.955, 165.379, 170.803, 176.226, 181.65, 187.074, 192.497, 197.921, 203.345, 208.763, 214.192, 219.616, 225.034, 230.458, 235.887, 241.311, 246.729, 252.158, 257.582, 263.005, 268.424, 273.853, 279.276, 284.7]);
__motion_NewBall_7.addPropertyArray("scaleX", [1.000000]);
__motion_NewBall_7.addPropertyArray("scaleY", [1.000000]);
__motion_NewBall_7.addPropertyArray("skewX", [0]);
__motion_NewBall_7.addPropertyArray("skewY", [0]);
__motion_NewBall_7.addPropertyArray("rotationConcat", [0]);
__motion_NewBall_7.addPropertyArray("blendMode", ["normal"]);
__motion_NewBall_7.addPropertyArray("cacheAsBitmap", [false]);
__motion_NewBall_7.addPropertyArray("opaqueBackground", [null]);
__motion_NewBall_7.addPropertyArray("visible", [true]);
var __animFactory_NewBall_7: AnimatorFactory = new AnimatorFactory(__motion_NewBall_7);
__animFactory_NewBall_7.transformationPoint = new Point(0.500000, 0.500000);
__animFactory_NewBall_7.addTarget(myClip, 0);
}
}
use:
...
import fl.motion.AnimatorFactory;
import fl.motion.MotionBase;
import fl.motion.Motion;
import flash.filters.*;
import flash.geom.Point;
theButton.addEventListener(MouseEvent.CLICK, on_press1);
var __motion_NewBall_7: MotionBase;
var __animFactory_NewBall_7: AnimatorFactory; // <-just the declaration was to be moved. not the definition
function on_press1(event: MouseEvent): void {
if (__motion_NewBall_7 == null) {
__motion_NewBall_7 = new Motion();
__motion_NewBall_7.duratio
Copy link to clipboard
Copied
move that AnimationFactory declaration outside your function just like you did with your MotionBase declaration.
Copy link to clipboard
Copied
nope, still doesn'r work, I get this error message:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at fl.motion::AnimatorBase/set time()
at fl.motion::AnimatorBase/play()
at fl.motion::AnimatorBase$/processCurrentFrame()
at fl.motion::AnimatorFactoryBase/addTargetInfo()
at fl.motion::AnimatorFactoryBase/addTarget()
at test2_scene10_Scene13_fla::MainTimeline/on_press1()[test2_scene10_Scene13_fla.MainTimeline::frame1:33]
Copy link to clipboard
Copied
I tested this script on both CC1214 and on CS6 and they both have the same problem. moving the var statements out of the function did not help but rather produced an additional error that I described above. at this point I'm clueless.
Copy link to clipboard
Copied
what code are you using and what's on line 33 of frame 1 that's triggering that error?
Copy link to clipboard
Copied
The code above is the entire code that I'm using. The stage have one button and one circle (myClip). The circle should drop down in a specific motion when clicking on the button, but when clicking on the button there is no motion. However, when the motion code part is outside of the function the movement of the circle is as expected. I'd like to control the motion and have it run only after clicking on the button. Maybe I'm using the wrong method but I don't know how.
Copy link to clipboard
Copied
copy and paste the code you're using and highlight line 33 of frame 1.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The error is on line 32 now since I played with the code moving things around.
Copy link to clipboard
Copied
don't use screenshots. copy and paste your code, in the future.
use:
var __animFactory_NewBall_7:AnimatorFactory; // <-just the declaration was to be moved. not the definition
outside your function and after creating your motion instance (inside your function body) use
__animFactory_NewBall_7=new AnimatorFactory(_motion_NewBall_7); // define it after the motion, _motion_NewBall_7 exists.
Copy link to clipboard
Copied
Still not good. I'm getting this error now. Scene 13, Layer 'Layer 1', Frame 1, Line 29, Column 491120: Access of undefined property _motion_NewBall_7.
Line 29 is in bold.
import fl.motion.AnimatorFactory;
import fl.motion.MotionBase;
import fl.motion.Motion;
import flash.filters.*;
import flash.geom.Point;
theButton.addEventListener(MouseEvent.CLICK, on_press1);
var __motion_NewBall_7: MotionBase;
var __animFactory_NewBall_7: AnimatorFactory; // <-just the declaration was to be moved. not the definition
function on_press1(event: MouseEvent): void {
if (__motion_NewBall_7 == null) {
__motion_NewBall_7 = new Motion();
__motion_NewBall_7.duration = 60;
__motion_NewBall_7.addPropertyArray("x", [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4.02143, -8.04286, -12.0603, -16.0857, -20.1071, -24.1246, -28.15, -35.6987, -43.2474, -50.7885, -58.3447, -65.8934, -73.4346, -80.9832, -88.5395, -96.0882, -103.637, -111.186, -118.727, -126.283, -133.824, -141.38, -148.929, -156.478, -164.026, -171.575, -179.124, -186.672, -194.221, -201.77, -209.311, -216.867, -224.416, -231.957, -239.506, -247.062, -254.611, -262.152, -269.708, -277.257, -284.805, -292.346, -299.903, -307.451, -315]);
__motion_NewBall_7.addPropertyArray("y", [0, 9.41071, 18.8214, 28.2227, 37.6429, 47.0536, 56.4549, 65.875, 75.2857, 84.6964, 94.1071, 103.518, 112.919, 122.339, 131.75, 124.157, 116.564, 108.979, 101.379, 93.7857, 86.2004, 78.6, 84.0237, 89.4474, 94.8656, 100.295, 105.718, 111.137, 116.56, 121.989, 127.413, 132.837, 138.261, 143.679, 149.108, 154.526, 159.955, 165.379, 170.803, 176.226, 181.65, 187.074, 192.497, 197.921, 203.345, 208.763, 214.192, 219.616, 225.034, 230.458, 235.887, 241.311, 246.729, 252.158, 257.582, 263.005, 268.424, 273.853, 279.276, 284.7]);
__motion_NewBall_7.addPropertyArray("scaleX", [1.000000]);
__motion_NewBall_7.addPropertyArray("scaleY", [1.000000]);
__motion_NewBall_7.addPropertyArray("skewX", [0]);
__motion_NewBall_7.addPropertyArray("skewY", [0]);
__motion_NewBall_7.addPropertyArray("rotationConcat", [0]);
__motion_NewBall_7.addPropertyArray("blendMode", ["normal"]);
__motion_NewBall_7.addPropertyArray("cacheAsBitmap", [false]);
__motion_NewBall_7.addPropertyArray("opaqueBackground", [null]);
__motion_NewBall_7.addPropertyArray("visible", [true]);
__animFactory_NewBall_7 = new AnimatorFactory(_motion_NewBall_7); // define it after the motion, _motion_NewBall_7 exists
__animFactory_NewBall_7.transformationPoint = new Point(0.500000, 0.500000);
__animFactory_NewBall_7.addTarget(myClip, 1);
}
}
Copy link to clipboard
Copied
use:
import fl.motion.AnimatorFactory;
import fl.motion.MotionBase;
import fl.motion.Motion;
import flash.filters.*;
import flash.geom.Point;
theButton.addEventListener(MouseEvent.CLICK, on_press1);
var __motion_NewBall_7: MotionBase;
var __animFactory_NewBall_7: AnimatorFactory; // <-just the declaration was to be moved. not the definition
function on_press1(event: MouseEvent): void {
if (__motion_NewBall_7 == null) {
__motion_NewBall_7 = new Motion();
__motion_NewBall_7.duration = 60;
__motion_NewBall_7.addPropertyArray("x", [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -4.02143, -8.04286, -12.0603, -16.0857, -20.1071, -24.1246, -28.15, -35.6987, -43.2474, -50.7885, -58.3447, -65.8934, -73.4346, -80.9832, -88.5395, -96.0882, -103.637, -111.186, -118.727, -126.283, -133.824, -141.38, -148.929, -156.478, -164.026, -171.575, -179.124, -186.672, -194.221, -201.77, -209.311, -216.867, -224.416, -231.957, -239.506, -247.062, -254.611, -262.152, -269.708, -277.257, -284.805, -292.346, -299.903, -307.451, -315]);
__motion_NewBall_7.addPropertyArray("y", [0, 9.41071, 18.8214, 28.2227, 37.6429, 47.0536, 56.4549, 65.875, 75.2857, 84.6964, 94.1071, 103.518, 112.919, 122.339, 131.75, 124.157, 116.564, 108.979, 101.379, 93.7857, 86.2004, 78.6, 84.0237, 89.4474, 94.8656, 100.295, 105.718, 111.137, 116.56, 121.989, 127.413, 132.837, 138.261, 143.679, 149.108, 154.526, 159.955, 165.379, 170.803, 176.226, 181.65, 187.074, 192.497, 197.921, 203.345, 208.763, 214.192, 219.616, 225.034, 230.458, 235.887, 241.311, 246.729, 252.158, 257.582, 263.005, 268.424, 273.853, 279.276, 284.7]);
__motion_NewBall_7.addPropertyArray("scaleX", [1.000000]);
__motion_NewBall_7.addPropertyArray("scaleY", [1.000000]);
__motion_NewBall_7.addPropertyArray("skewX", [0]);
__motion_NewBall_7.addPropertyArray("skewY", [0]);
__motion_NewBall_7.addPropertyArray("rotationConcat", [0]);
__motion_NewBall_7.addPropertyArray("blendMode", ["normal"]);
__motion_NewBall_7.addPropertyArray("cacheAsBitmap", [false]);
__motion_NewBall_7.addPropertyArray("opaqueBackground", [null]);
__motion_NewBall_7.addPropertyArray("visible", [true]);
__animFactory_NewBall_7 = new AnimatorFactory( __motion_NewBall_7); // define it after the motion, _motion_NewBall_7 exists
__animFactory_NewBall_7.transformationPoint = new Point(0.500000, 0.500000);
__animFactory_NewBall_7.addTarget(myClip, 1);
}
}
Copy link to clipboard
Copied
Great catch. It works now! thank you so much
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now