-
stopping a blur tween
In this game I dynamically load 9 random pictures onto the stage. They all start off with maximum blur. The idea is that when the user hears a sentence the pictures gradually lose their blur. The sooner the correct picture is clicked on, the higher the score.
My problem is, I can't stop the tween when the user clicks on a picture. I've tried it successfully on a much simpler fla, where the images are already on the stage and not loaded from an external source.
Can anyone help?
Here's my extracted code - the source fla is way too long to attach.
Actionscript Code:
import mx.transitions.Tween; import mx.transitions.easing.Strong; import flash.filters.*; import mx.controls.Loader;
var totalBlur:Number = 100;//100 is maximum blur, I think var noBlur :Number = 0;
var blur:BlurFilter = new BlurFilter(totalBlur, totalBlur, 3); var blurTween:Tween;
function removeBlur() // this works fine { var blurTween= new Tween(blur, "blurX", Regular.easeIn, blur.blurX, noBlur, 8.0, true); blurTween.onMotionChanged = function() { blur.blurY = blur.blurX; randomPic.filters = new Array(blur); } // end of removeBlur function
function stopBlurTween() // this does not stop the tween!!!
{ trace("stopBlur function called"); // the function gets called okay.
for (f:Number = 0;f<9;f++) { _root.container3_mc["randomPic"+f].blurTween.stop(); } } // end of stopBlur function
for (var i:Number = 0; i<9; i++) { this.randomPic = _root.container3_mc.createEmptyMovieClip ("randomPic"+i, i); randomPic._x = (offsetX*(i%cols))+60;// this sets how far in from left the grid is randomPic._y = (offsetY*Math.floor (i/cols))+30; removeBlur (randomPic);
var mcLoader:MovieClipLoader = new MovieClipLoader (); var listener:Object = new Object (); listener.onLoadInit = function (target:MovieClip):Void { target.onRelease = function () { stopBlurTween(); if (ready) { attempts = attempts+1;
if (this._name == "randomPic"+correctAnswer) { trace "correct"); } else { trace ("false"); }; } } }; }; mcLoader.addListener (listener); mcLoader.loadClip (randomPicArray[i],randomPic); // loads jpegs from a random arrayinto the 'randomPic' movie clip } clearInterval (myTimer); myTimer = setInterval (playRandomSound, 1000);
var myRandomSound:Sound = new Sound (); myRandomSound.onLoad = function (success:Boolean) { if (success) { myRandomSound.start (); myRandomSound.onSoundComplete = function () { ready = true; }; // changed this from my_sound but it makes no difference - why? } }; function playRandomSound () { ready = false; clearInterval (myTimer); myRandomSound.loadSound (randomSoundArray[correctAnswer],true); }
-
Senior Member
try:
blurTween.stop();
becasue you are using this:
var blurTween= new Tween(blur, "blurX", Regular.easeIn, blur.blurX, noBlur, 8.0, true);
and the stop function is right below it you do no t need to use any type of for loop.
Last edited by hts5000; 12-27-2010 at 02:51 PM.
Reason: Incomplete answer
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|