A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: [Resolved] ActionScript tweening wihout onClipEvent(enterFrame). Is it possible?

  1. #1
    Senior Member Leo Lima's Avatar
    Join Date
    Jul 2000
    Location
    São Paulo, Brazil
    Posts
    745
    Hey! I'd like to know if it's possible to do ActionScript-based tweening (like moving something frrom xs = random(100) to xf = random(600), 5 units per frame) without using onClipEvent (enterFrame). And if so, could you provide a sample code?

    I can do that by the following code:
    Code:
    onClipEvent (load) {
      this.xs = this._x;
      this.xf = random(100) + this.xs;
    }
    onClipEvent (enterFrame) {
      if (this.xf > this._x) this._x += random(5);
      if (this.xf < this._x) this._x = this.xf;
      trace(this.percent_complete = Math.floor((this._x - this.xs)*100/(this.xf-this.xf)) + "%");
    }
    Once the movement is complete, it keeps doing useless stuff. How do I get something better? I could create an emptyMovieClip to contrl the movement and delete it after the mvmt completes, but that is so weird... Anyone has anything better?

    Thanks,
    Leo


  2. #2
    (sic) Covenent's Avatar
    Join Date
    Dec 2000
    Location
    Ireland
    Posts
    709
    With Flash MX`s new event model you can dynamically set/change/delete an instances events. So if your making your movie for the Flash 6 player use the following instead:

    Code:
    // place code on the timeline 'myClip' is on, and not on the 'myClip' itself
    myClip.xs = myClip._x;
    myClip.xf = random(100)+myClip.xs;
    
    
    myClip.onEnterFrame = function () {
      if (this.xf > this._x) this._x += random(5);
      if (this.xf < this._x) this._x = this.xf;
      var percentComplete = (this._x/this.xf)*100;
      if (percentComplete == 100) { delete this.onEnterFrame; }
    }
    But if you want to aim your movie for the Flash 5 player use this instead:

    Code:
    // place code on the instance itself
    onClipEvent (load) {
      this.xs = this._x;
      this.xf = random(100) + this.xs;
    }
    onClipEvent (enterFrame) {
    	  var percentComplete = (this._x/this.xf)*100;
    	  
    	  if (percentComplete == 100) {
    		  // do nothing
    	  } else {
    		  if (this.xf > this._x) this._x += random(5);
    		  if (this.xf < this._x) this._x = this.xf;
    	  }
    }

  3. #3
    Senior Member Leo Lima's Avatar
    Join Date
    Jul 2000
    Location
    São Paulo, Brazil
    Posts
    745
    Flash 5 is old already (even if macromedia didn't release a player for linux ), so I might use that. Thanks a lot!

    And even your flash5 code does something (a check is something), and that (with a LOT of other things) can consume CPU too much...

    Regards,
    Leo

  4. #4
    (sic) Covenent's Avatar
    Join Date
    Dec 2000
    Location
    Ireland
    Posts
    709
    Other alternatives are setInterval/clearInterval for MX, and using keyframes with actions to control the animation by moving the playhead. The keyframe method is actually much more processor friendly for Flash 5 as you can stop the testing, the reason I provided you with onClipEvent method was because thats how you wrote your original code so I presumed you wanted it in the same format.

    Cheers,

  5. #5
    Senior Member Leo Lima's Avatar
    Join Date
    Jul 2000
    Location
    São Paulo, Brazil
    Posts
    745
    What's that set/clearInterval? Never saw them...

    And I don't like my stage filled with empty MCs and since Flash 5 I use to get everything that needs some frames (like AS Tween) inside a unique controlMC. But that gets stuffed and buggy and laggy and ****ty And if flash6 gets something better to handle my case (like the delete on(frame)), why not use it? People should know that they need to move on and not use something old

    Regards,
    Leo.

  6. #6
    (sic) Covenent's Avatar
    Join Date
    Dec 2000
    Location
    Ireland
    Posts
    709
    You can use setInterval to tell a function to be called every x amount of miliseconds (timeline independent), and you can use clearInterval to stop an interval. I will give a quick example here, but you should look at MX`s reference panel for more in depth information:

    Code:
    traceName = function (firstName, lastName) {
    trace("Your name is "+firstName+" "+lastName);
    }
    myInterval = setInterval(traceName, 1000, "John", "Doe");
    
    this.onMouseDown = function () {
    clearInterval(myInterval);
    }

  7. #7
    Senior Member Leo Lima's Avatar
    Join Date
    Jul 2000
    Location
    São Paulo, Brazil
    Posts
    745
    Very interesting, I shall use that constantly

    Thanks and best regards,
    Leo

  8. #8
    Senior Member
    Join Date
    Jan 2001
    Posts
    106

    in MX its all easy

    hi guys,

    its very simple in MX...that too the enterFrame problem is easily tackled in it...

    _root.createEmptyMovieClip(test,1);

    _root.test.onEnterFrame()=function(){
    // place the code here for enterframe
    //once the task is over place the following line
    delete _root.test.onEnterFrame();
    }



    i hope this helps you...the code deletes the event onEnterFrame....which solves the problem of CPU time..



    cheeeeeers
    gnana

  9. #9
    (sic) Covenent's Avatar
    Join Date
    Dec 2000
    Location
    Ireland
    Posts
    709

    Re: in MX its all easy

    Originally posted by gnana
    hi guys,

    its very simple in MX...that too the enterFrame problem is easily tackled in it...

    _root.createEmptyMovieClip(test,1);

    _root.test.onEnterFrame()=function(){
    // place the code here for enterframe
    //once the task is over place the following line
    delete _root.test.onEnterFrame();
    }



    i hope this helps you...the code deletes the event onEnterFrame....which solves the problem of CPU time..



    cheeeeeers
    gnana
    Yeah I already talked about that method earlier:

    Originally posted by Covenent
    With Flash MX`s new event model you can dynamically set/change/delete an instances events. So if your making your movie for the Flash 6 player use the following instead:

    Code:
    // place code on the timeline 'myClip' is on, and not on the 'myClip' itself
    myClip.xs = myClip._x;
    myClip.xf = random(100)+myClip.xs;
    
    
    myClip.onEnterFrame = function () {
      if (this.xf > this._x) this._x += random(5);
      if (this.xf < this._x) this._x = this.xf;
      var percentComplete = (this._x/this.xf)*100;
      if (percentComplete == 100) { delete this.onEnterFrame; }
    }

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