I created a class that does Scale animation on movie clips using the setInterval function. I then created a class that turns text into individual movie clips for each character. Each class does what it's supposed to do when used separately. Within the text class, i then try to access methods of the scale class. My goal is to be able to adjust scaling for each character movie clip. In the text class, i create an array that holds references to each char based movie clip. I then iterate through the array calling the scaling functions on each member of the array. Everything seems to work ok till the scale class uses setInterval. After the call to setInterval, nothing happens. It seems that maybe setInterval doesnt have the correct scope on which to act. The relevent code snipits are below: TextEffect class -- charArray is the array holding the movie clip references import ScaleTransformArray; class TextEffect { private var clipReference:MovieClip; private var char:MovieClip; //reference to timeline text is in public function TextEffect(target:MovieClip) { clipReference = target; } ..... public function scaleWriter(charArray:Array, finalx:Number, finaly:Number, steps:Number, offset:Number, durationPos:Number, durationNeg:Number, waitPos:Number, waitNeg:Number, iterations:Number):Void { var temp:Array; var returnArray:Array; var scales:ScaleTransformArray; for(var i:Number=0; i < charArray.length; i++) { temp = new Array(); returnArray = new Array(); scales = new ScaleTransformArray(charArray); temp.push(finalx); temp.push(finaly); returnArray = scales.generateArray(temp, steps); scales.applyArrayScale(returnArray, offset, durationPos, durationNeg, waitPos, waitNeg, iterations); charArray._visible = true; updateAfterEvent(); } } .... } Scale class -- scaleArray is an array that holds all the scaling positions. applyArrayScaleHelper handles the animation and has setInterval functions of its own. class ScaleTransformArray { ... public function ScaleTransformArray(targetClip:MovieClip) { clipReference = targetClip; origScaleXY = new Array(); origScaleXY.push(targetClip._xscale); origScaleXY.push(targetClip._yscale); } .... public function applyArrayScale(scaleArray:Array, initialWait:Number, durationPos:Number, durationNeg:Number, waitPos:Number, waitNeg:Number, iterations:Number):Void { startTime = getTimer(); flag = 1; totalIter = 0; working = 0; arrayInterval = setInterval(this, "applyArrayScaleHelper", 1000, scaleArray, initialWait, durationPos, durationNeg, waitPos, waitNeg, iterations); } ... } The helper function never gets called and, thus, no animation happens. Using debug, i can see that scaleArray has the correct values for the char movie clips. Transforms hardcoded directly to clipReference work fine, but the setInterval fctn still does nothing.
[quoted text, click to view] Excessus wrote: > I created a class that does Scale animation on movie clips using the
Hi, i had the same problem setInterVal function not being called in a class, and fixed it this way: ---code snppet------------------ var intervalID = setInterval(function () { if (targetC._alpha<to) { targetC._alpha += amount; } else { targetC._alpha = Math.round(to); clearInterval(intervalID); } }, speed); --------------//----------------- nice class you are working on btw. i would like something like that...
thanks for the idea. though im not sure that solution will work well in this case. it seems like you just define the function to be called in the setInterval call. my concern about that method is that the function i want to call is large and it sets up to three different Intervals. seems like it would get quite convoluted trying put all that in one main function call. i was thinking that the easiest way might be to just put the methods into the textEffect class. its against my standards, but seems like it might be the only way to make it somewhat simple...
alright, i came at the problem from the next highest level. instead of importing the scale class into the TextEffect class, i used what the TextEffect class returns after placing the chars. in the main movie, i iterate through the returned array thusly: var Effect:TextEffect = new TextEffect(this); var array1:Array = new Array(); array1 = Effect.createTextClips(newstring, format, 150, 100, "letter"); array1 = Effect.placeText(array1, 150, 100, format); var scale:ScaleTransformArray; for(var i:Number=0; i < array1.length; i++) { scale = new ScaleTransformArray(array1); array1._visible = true; var temp4:Array = new Array(); temp4 = scale.generateArray(temp3, 55); scale.applyArrayScale(temp4, 1000, 1000, 1000, temp1, temp2, 12); } i omitted the temp defs that are just for randomness. i figured this code would take each char movie clip, apply a scale object, and do somewhat random effect different for each char. however, it only affects the last clip in array1. in debugging, the code seems to get to the first setInterval call correctly for each array1, but it only animates the last element. any ideas on why its working that way?
Don't see what you're looking for? Try a search.
|