在功能内部不起作用的运动

时间:2015-06-03 17:47:05

标签: actionscript-3 flash

所以我有这个动作脚本,我从Cs6复制为“将动作复制为AS3”。它工作正常,直到我尝试用鼠标事件功能控制它。那我错过了什么?它在功能之外工作正常,但根本没有。

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

1 个答案:

答案 0 :(得分:0)

以下是问题的解决方案:我不得不将var __animFactory_NewBall_7: AnimatorFactory = new AnimatorFactory(__motion_NewBall_7);分为两部分:var __animFactory_NewBall_7: AnimatorFactory;位于函数外部,var __animFactory_NewBall_7: AnimatorFactory = new AnimatorFactory(__motion_NewBall_7);位于函数内部

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


}