【发布时间】:2015-08-25 01:12:01
【问题描述】:
更新
我有一个大杂乱的代码,我想通过实例化一次CubeEaseOut Class 来加速。我通过 ff 做到这一点:
var myClass = new CubeEaseOut()
myClip.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
myClip2.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
myClip3.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
function onMouseOver(e:Event){
//made changes here
myClass.initializer(e.currentTarget, ["scaleX",1.5,"height",200]);
}
因此,每当我在任何剪辑上移动鼠标时,都会调用 CubeEaseOut 类中名为 initializer() 的函数。
在CubeEaseOut 类中,我有一个代码可以在ENTER_FRAME 上进行一次午餐,然后定期调用函数animateThis()。
package;
import goes here...
class CubeEaseOut extends Sprite {
var here...
public function new(){
super();
addEventListener(Event.ENTER_FRAME, animateThis);
}
public function initializer(mc:Dynamic, vars:Array<Dynamic>()){
vars[1] //this is a Float with value 1.5
mc[vars[0]] //is mc.scaleX
//some other code
//notice many variables received here are needed by other functions
//but if I make this public, or placed outside functions, every call
//on this function will overwrite previous values
//other variables here
var sp:Float = (vars[1] - mc[vars[0]])/50
}
private function animateThis(e:Event){
//some other code
//many variables from initialize() function is needed here
iter++
mc[vars[1]] += sp*iter
}
}
问题是,要使animateThis() 工作,它需要来自initializer() 的变量。我如何将变量从initializer() 传递到animateThis() 而不会在下次调用initializer() 时覆盖以前的变量?
尝试:
- 我尝试使用全局变量,但这会使事情变得一团糟。
- 将 ENTER_FRAME 放在 initializer() 函数中,但事实证明 ENTER_FRAME 将被称为我的时间 - CPU 密集型。
- 创建了该类的多个实例 - 也是 CPU 密集型的。
- 尝试使用 this.aVar,aVar 会被下一次调用覆盖。
其他信息:
我正在做的完整代码和这个类似
Animation code not fired when mouse is out Clip1 but mouse is inside clip 2
但我现在正在实现类和 ENTER_FRAME。
【问题讨论】:
-
是的,我会的,我正在使用您的建议完成我的代码移植。结果出来后我会回来的。
-
@GurtejSingh 用户提出问题会收到有关他们收到的答案的通知。我们不必向网站发送垃圾邮件“看看我的答案!”厘米。
-
@null 对不起!我只是确保用户确实看到了我发布的答案。会小心前行。道歉。
标签: performance actionscript-3 actionscript haxe openfl