performance - How to pass a variables to a function called by ENTER_FRAME without override -
updated
i have got big cluttery code want speed instantiating cubeeaseout
class once. through 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]); }
so whenever move mouse on of clips, function named initializer()
inside cubeeaseout
class called.
inside cubeeaseout
class, have got code lunches on enter_frame
once periodically call function 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 float value 1.5 mc[vars[0]] //is mc.scalex //some other code //notice many variables received here needed other functions //but if make public, or placed outside functions, every call //on function 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 initialize() function needed here iter++ mc[vars[1]] += sp*iter } }
the thing is, animatethis()
work, needs vars initializer()
. how pass variables initializer()
animatethis()
without next call initializer()
overriding previous vars?
attemps:
- i tried use global vars messes things up.
- place enter_frame inside initializer() function turns out enter_frame called times - cpu intensive.
- created several instance of class - cpu intensive well.
- tried using this.avar, avar gets overridden next call.
additional info:
the full code doing similar 1
animation code not fired when mouse out clip1 mouse inside clip 2
but implementing class , enter_frame.
updated code below. far understand, want use same class cubeeaseout
manage multiple animations. i've tried (not tested), create array of objects of data being passed class. in each object, store movie clip passed, , data passed each movie clip. every time initializer called checks whether data movie clip exists in array. if not, adds movie clip , it's data array. if finds movie clip, assigns object current animating object array , not overwrite it's data. note may limit animation run 1 movie clip @ time.
you can choose run loop inside enter frame method , perform animations objects inside array.
import goes here... class cubeeaseout extends sprite { private var objectstoanimate:array = new array(); private var currentmcdata:object; public function new(){ super(); addeventlistener(event.enter_frame, animatethis); } public function initializer(mc:dynamic, vars:array<dynamic>()){ (var i:uint = 0; < objectstoanimate.length; i++) { if (objectstoanimate[i].movieclip != mc) { var dataobj:object = new object(); dataobj.movieclip = mc; dataobj.datavars = vars; objectstoanimate.push(dataobj); } else if (objectstoanimate[i].movieclip == mc) this.currentmcdata = objectstoanimate[i]; } } private function animatethis(e:event){ //codes here trace(this.currentmcdata.vars); // or run loop , animate movie clips. } }
hope helps.
Comments
Post a Comment