A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [f8]

  1. #1
    Senior Member
    Join Date
    Aug 2002
    Location
    Philadelphia, PA
    Posts
    274

    [f8]

    I have 7 movieclips on my stage and have their original x & y positions stored in an array. I have a function that runs 7 times and moves each of the clips off the stage in a random direction, fades them out, and blurs them. When that is complete another function is called that moves them all back, fades them back in and un-blurs them. Only problem is that the seventh one isn't moving back for some reason. I've been looking at this for what seems like ever and am getting no where. Any help would be awesome. My code is below. It seems a bit long winded for what I'm trying to accomplish, if anyone has any suggestions for shortening it up I'm all ears....and eyes.

    code:

    import flash.filters.BlurFilter;
    import mx.transitions.Tween;
    import mx.transitions.easing.*;

    var currentNum:Number = 1;
    var stageWidth:Number = Stage.width;
    var stageHeight:Number = Stage.height;
    var xArray:Array = new Array();
    var yArray:Array = new Array();
    var countInterval:Number;

    function randRange(_min:Number, _max:Number):Number {
    var randomNum:Number = Math.floor(Math.random() * (_max - _min + 1)) + _min;
    return randomNum;
    }

    function moveOn(_whichClip:String) {

    var isXSet:Boolean = false;
    var isYSet:Boolean = false;
    var xPos:Number = randRange(-1000, 1000);
    var yPos:Number = randRange(-1000, 1000);
    var blurX:Number = 6;
    var blurY:Number = 6;
    var quality:Number = 3;
    var filter:BlurFilter = new BlurFilter(blurX, blurY, quality);
    var filterArray:Array = new Array();
    filterArray.push(filter);
    xArray.push(_root[_whichClip]._x);
    yArray.push(_root[_whichClip]._y);

    //trace("original xPos is " + xPos);
    //trace("original yPos is " + yPos);

    _root.createEmptyMovieClip("checker_mc", _root.getNextHighestDepth());
    _root.checker_mc.onEnterFrame = function() {
    (xPos >= 0 && xPos <= stageWidth) ? isXSet = false : isXSet = true;
    (yPos >= 0 && yPos <= stageHeight) ? isYSet = false : isYSet = true;
    if (!isXSet && !isYSet) {
    if (xPos >= 0 && xPos <= stageWidth && !isXSet) {
    xPos = randRange(-1000, 1000);
    trace("new xPos is " + xPos);
    }
    if (yPos >= 0 && yPos <= stageHeight && !isYSet) {
    yPos = randRange(-1000, 1000);
    trace("new yPos is " + yPos);
    }
    } else {
    var moveToX:Tween = new Tween(_root[_whichClip], "_x", Strong.easeOut, _root[_whichClip]._x, xPos, 1, true);
    var moveToY:Tween = new Tween(_root[_whichClip], "_y", Strong.easeOut, _root[_whichClip]._y, yPos, 1, true);
    var fadeOut:Tween = new Tween(_root[_whichClip], "_alpha", Strong.easeOut, _root[_whichClip]._alpha, 0, 1, true);
    _root[_whichClip].filters = filterArray;
    }
    }

    }

    function moveBack() {
    var blurX:Number = 0;
    var blurY:Number = 0;
    var quality:Number = 3;
    var filter:BlurFilter = new BlurFilter(blurX, blurY, quality);
    var filterArray:Array = new Array();
    filterArray.push(filter);
    for (var i:Number = 1; i <= 7; i++) {
    var arrayNum:Number = i - 1;
    var whichClip:String = "square_" + i + "_mc";
    trace(whichClip + " should be at " + xArray[arrayNum] + " _x " + yArray[arrayNum] + " _y");
    var moveToX:Tween = new Tween(_root[whichClip], "_x", Strong.easeOut, _root[whichClip]._x, xArray[arrayNum], 1, true);
    var moveToY:Tween = new Tween(_root[whichClip], "_y", Strong.easeOut, _root[whichClip]._y, yArray[arrayNum], 1, true);
    var fadeOut:Tween = new Tween(_root[whichClip], "_alpha", Strong.easeOut, _root[whichClip]._alpha, 100, 1, true);
    _root[whichClip].filters = filterArray;
    }
    }

    function whichClip() {
    if (currentNum <= 7) {
    var whichClip:String = "square_" + currentNum + "_mc";
    currentNum++;
    moveOn(whichClip);
    } else {
    clearInterval(countInterval);
    moveBack();
    }
    }

    countInterval = setInterval(whichClip, 100);

    Last edited by quovadimus02; 03-12-2009 at 11:45 AM.
    Ohhhh jeez.......not again.

  2. #2
    Observe Alot By Watching ryanmacflashkit's Avatar
    Join Date
    May 2006
    Location
    In the Jungle
    Posts
    172
    Hi Quav,

    Just a quick post as I'm working at the moment...I always try to keep all my counts starting at 0, have rearranged it a bit, it seems to working now. Your if (currentNum <= 7) makes more sense like this.

    This code seems to work.

    import flash.filters.BlurFilter;
    import mx.transitions.Tween;
    import mx.transitions.easing.*;

    var currentNum:Number = 0;
    var stageWidth:Number = Stage.width;
    var stageHeight:Number = Stage.height;
    var xArray:Array = new Array();
    var yArray:Array = new Array();
    var countInterval:Number;

    function randRange(_min:Number, _max:Number):Number {
    var randomNum:Number = Math.floor(Math.random() * (_max - _min + 1)) + _min;
    return randomNum;
    }

    function moveOn(_whichClip:String) {

    var isXSet:Boolean = false;
    var isYSet:Boolean = false;
    var xPos:Number = randRange(-1000, 1000);
    var yPos:Number = randRange(-1000, 1000);
    var blurX:Number = 6;
    var blurY:Number = 6;
    var quality:Number = 3;
    var filter:BlurFilter = new BlurFilter(blurX, blurY, quality);
    var filterArray:Array = new Array();
    filterArray.push(filter);
    xArray.push(_root[_whichClip]._x);
    yArray.push(_root[_whichClip]._y);

    //trace("original xPos is " + xPos);
    //trace("original yPos is " + yPos);

    _root.createEmptyMovieClip("checker_mc", _root.getNextHighestDepth());
    _root.checker_mc.onEnterFrame = function() {
    (xPos >= 0 && xPos <= stageWidth) ? isXSet = false : isXSet = true;
    (yPos >= 0 && yPos <= stageHeight) ? isYSet = false : isYSet = true;
    if (!isXSet && !isYSet) {
    if (xPos >= 0 && xPos <= stageWidth && !isXSet) {
    xPos = randRange(-1000, 1000);
    trace("new xPos is " + xPos);
    }
    if (yPos >= 0 && yPos <= stageHeight && !isYSet) {
    yPos = randRange(-1000, 1000);
    trace("new yPos is " + yPos);
    }
    } else {
    var moveToX:Tween = new Tween(_root[_whichClip], "_x", Strong.easeOut, _root[_whichClip]._x, xPos, 1, true);
    var moveToY:Tween = new Tween(_root[_whichClip], "_y", Strong.easeOut, _root[_whichClip]._y, yPos, 1, true);
    var fadeOut:Tween = new Tween(_root[_whichClip], "_alpha", Strong.easeOut, _root[_whichClip]._alpha, 0, 1, true);
    _root[_whichClip].filters = filterArray;
    }
    }

    }

    function moveBack() {
    var blurX:Number = 0;
    var blurY:Number = 0;
    var quality:Number = 3;
    var filter:BlurFilter = new BlurFilter(blurX, blurY, quality);
    var filterArray:Array = new Array();
    filterArray.push(filter);
    for (var i:Number = 0; i <= 6; i++) {
    var arrayNum:Number = i;
    var whichClip:String = "square_" + i + "_mc";
    trace(whichClip + " should be at " + xArray[arrayNum] + " _x " + yArray[arrayNum] + " _y");
    var moveToX:Tween = new Tween(_root[whichClip], "_x", Strong.easeOut, _root[whichClip]._x, xArray[arrayNum], 1, true);
    var moveToY:Tween = new Tween(_root[whichClip], "_y", Strong.easeOut, _root[whichClip]._y, yArray[arrayNum], 1, true);
    var fadeOut:Tween = new Tween(_root[whichClip], "_alpha", Strong.easeOut, _root[whichClip]._alpha, 100, 1, true);
    _root[whichClip].filters = filterArray;
    }
    }

    function whichClip() {
    if (currentNum <= 7) {
    var whichClip:String = "square_" + currentNum + "_mc";
    currentNum++;
    moveOn(whichClip);
    } else {
    clearInterval(countInterval);
    moveBack();
    }
    }

    countInterval = setInterval(whichClip, 100);



    Hope that helps mate
    Kind Regards
    Ryan Mac

    Big shots are just little shots that keep shooting.
    http://www.macmedia.co.za

  3. #3
    Senior Member
    Join Date
    Aug 2002
    Location
    Philadelphia, PA
    Posts
    274
    Awesome, that worked great. Thanks for your help.
    Ohhhh jeez.......not again.

  4. #4
    Observe Alot By Watching ryanmacflashkit's Avatar
    Join Date
    May 2006
    Location
    In the Jungle
    Posts
    172
    Its a cool idea...happy to help, enjoy the weekend!
    Kind Regards
    Ryan Mac

    Big shots are just little shots that keep shooting.
    http://www.macmedia.co.za

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center