Flash Sleep Function

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Hey all. Did a search and I can't find what I am looking for.

I need a sleep type function in Flash MX. What I am trying to do is animate a movie clip moving to a specific point. The point it needs to move to is retrieved from an XML document.

Code: [ Select ]
function animateCard(tPos){
    startY = _root.card_mc._y * -1;
    startX = _root.card_mc._x;
    _root.output += "\nStart Y: " + startY ; // debug
    _root.output += "\nStart X: " + startX ; // debug
    for (i = 0; i < tPos; i++){
     _root.card_mc._y = i;
     
    }
}
  1. function animateCard(tPos){
  2.     startY = _root.card_mc._y * -1;
  3.     startX = _root.card_mc._x;
  4.     _root.output += "\nStart Y: " + startY ; // debug
  5.     _root.output += "\nStart X: " + startX ; // debug
  6.     for (i = 0; i < tPos; i++){
  7.      _root.card_mc._y = i;
  8.      
  9.     }
  10. }


This is the function I am using. The problem is that the loop executes so quickly it happens almost instantly.

Any ideas?
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

onEnterFrame.

Works on the movie FPS(frames per second). If the FPS is 20 the function assigned to the onEnterFrame event will run (approx) 20 times per second.
replacing the loop,
Code: [ Select ]
_root.card_mc.tPos = tPos;
_root.card_mc.onEnterFrame = function(){
  if(this._y < this.tPos){
   this._y++;
  }else{
   delete this.onEnterFrame;
  }
}
  1. _root.card_mc.tPos = tPos;
  2. _root.card_mc.onEnterFrame = function(){
  3.   if(this._y < this.tPos){
  4.    this._y++;
  5.   }else{
  6.    delete this.onEnterFrame;
  7.   }
  8. }


onEnterFrame is as close to a sleep as flash gets.(unless you play with setInterval... headache..) Loops finish running before any changes are actually made to the display.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Thanks for that. Readin your post now I realised how to do it. Just couldn't get my brain to think it!

Thanks again for that, will do it now!
  • Jaw
  • Graduate
  • Graduate
  • User avatar
  • Posts: 132
  • Loc: Minneapolis, MN

Post 3+ Months Ago

I'm sure you figured it out but here is a little help for anyone else who needs it. Cheers.

Code: [ Select ]
//----The Deep Freeze by Jaw (jake.at.elementsmedia.net)
this.onEnterFrame = function() {
    theActiveGoods();
    deepfreeze = 1;
};
this.onMouseDown = function() {
    if (deepfreeze == 1) {
        //Mouse click stops animation
        delete this.onEnterFrame;
        deepfreeze = 0;
    } else {
        //Mouse click starts animation
        this.onEnterFrame = function() {
            theActiveGoods();
            deepfreeze = 1;
        };
    }
};
  1. //----The Deep Freeze by Jaw (jake.at.elementsmedia.net)
  2. this.onEnterFrame = function() {
  3.     theActiveGoods();
  4.     deepfreeze = 1;
  5. };
  6. this.onMouseDown = function() {
  7.     if (deepfreeze == 1) {
  8.         //Mouse click stops animation
  9.         delete this.onEnterFrame;
  10.         deepfreeze = 0;
  11.     } else {
  12.         //Mouse click starts animation
  13.         this.onEnterFrame = function() {
  14.             theActiveGoods();
  15.             deepfreeze = 1;
  16.         };
  17.     }
  18. };

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 8 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.