A Flash Developer Resource Site

Results 1 to 14 of 14

Thread: Loop for rotation and scaling - AS code check

  1. #1
    Member
    Join Date
    Mar 2003
    Posts
    53

    Loop for rotation and scaling - AS code check

    Good day to all of you Flashers,

    I'm trying to make a MC rotate 5 (five) times and enlarge it with each iteration. After 5 rotations the MC should stop and the visitor is redirected to another page.
    So far I've constructed this code:

    onClipEvent(enterFrame) {
    for (i = 0; i <5; ++i) {
    this._rotation += 10;
    this._xscale = this._xscale + 1;
    this._yscale = this._yscale + 1;
    }
    }

    The rotation works fine, and the size of the MC gets enlarged.
    BUT THE ROTATIONS DOES NOT STOP AFTER 5 ROTATIONS!!!
    I guess I must be doing something wrong somewhere...

    Can somebody finish this code for me?
    Thanks

    Dubya

  2. #2
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    Code:
    onClipEvent(enterFrame){
         this._rotation+=10;
         timesaround=Math.floor(this._rotation/360);
         this._xscale=this._xscale+(timesaround*5);
         this._yscale=this._yscale+(timesaround*5);
         if (timesaround==5){
              delete this.onEnterFrame;
         }
    }
    try this...It's untested, but it should work, let me know and if it doesn't, ill fix it when i get home from school

  3. #3
    Member
    Join Date
    Mar 2003
    Posts
    53
    Hmmm, like you said... i'ts untested and unfortunately it doesn't work.

    Rotation doesn't stop after 5 turns.
    And enlargement of size works only patially: first time around the MC grows smaller!! in size and then grows bigger...

    Seems there's some testing to do, after school of course!

    G's

    Dubya

  4. #4
    Senior Member pellepiano's Avatar
    Join Date
    Feb 2000
    Location
    Stockholm, Sweden
    Posts
    15,151
    Using a loop, will make all the animations in one step, and repeat everything for each frame. Instead use a simple if statement.

    onClipEvent (load) {
    i = 1;
    }
    onClipEvent (enterFrame) {
    if (i<5) {
    this._rotation += 10;
    this._xscale = this._xscale+1;
    this._yscale = this._yscale+1;
    i++;
    }
    }

    -Pelle Piano
    // Image Gallery
    www.studiobild.com
    // Photo Blog
    http://talesofthepixel.blogspot.com

  5. #5
    Member
    Join Date
    Mar 2003
    Posts
    53
    Hmm, once again... it's a no go!

    I've placed the code with copy&paste into my fla.
    When I call the page the MC rotates a few degrees (all in all just a minor movement!) and then the whole thing stops...

    So, the search continues...

    G's

    Dubya

  6. #6
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    third time lucky
    Code:
    onClipEvent (load) 
    {
    	turns = 5;
    }
    onClipEvent (enterFrame) 
    {
    	if (turns)
    	{
    		this._rotation += 10;
    		if(!this._rotation) turns--;
    		this._xscale = ++this._yscale;
    	}
    }
    Last edited by Lexicon; 09-12-2005 at 09:21 AM.
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  7. #7
    14 year old W.I.Z!
    Join Date
    Jul 2005
    Location
    USA
    Posts
    227
    try this:
    Code:
    onClipEvent (enterFrame){
    	for (i=0; i<=5; i++) {
    		this.rotation += 10;
    		this._xscale += 5;
    		this._yscale += 5;
    		i++;
    	}
    }
    If this does'nt work, I'll try figuring it out!
    Excuse my horrible spelling....you can blame my English teacher for that!

  8. #8
    14 year old W.I.Z!
    Join Date
    Jul 2005
    Location
    USA
    Posts
    227
    Ya, I'll try figuring it out when I get home from school like 'MyFriendIsATaco'. If it works...nothing else to say
    Excuse my horrible spelling....you can blame my English teacher for that!

  9. #9
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    that won't work cobra and I don't even need to run it to see that.



    I think maybe you should test your code before posting it and you'll see the obvious flaws.
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  10. #10
    Member
    Join Date
    Mar 2003
    Posts
    53
    First, let's start with the good news: the code from Lexicon works (yiiihaaaa!).

    But it still leaves me with one final question: where do i put my
    getURL(www.stineco.be/paling/einde.php, "_self");
    code?

    G's

    Dubya

  11. #11
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    Because you are using an onClipEvent(enterframe) you need to check that the getUrl runs only once or you could cause a nice browser crash!

    like this...

    Code:
    onClipEvent (load) 
    {
    	runonce = true;
    	turns = 5;
    }
    onClipEvent (enterFrame) 
    {
    	if (turns)
    	{
    		this._rotation += 10;
    		if(!this._rotation) turns--;
    		this._xscale = ++this._yscale;
    	}
    	else
    	{
    		if(runonce)
    		{
    			runonce=false;
    			getURL("http://www.stineco.be/paling/einde.php", "_self");
    		}
    	}
    }
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  12. #12
    Member
    Join Date
    Mar 2003
    Posts
    53
    Thanks Lexicon!

    It all works very fine now.

    Funny though, my initial post was based on stuff I gathered/learned from Derek Franklin's book 'Flash MX ActionScripting - Advanced'.

    PellePiano, who's anything but an absolute beginner at AS, seemed to walk down the same path I was heading. But his code didn't work either...

    And then Lexicon's code takes a very different road, but it gets me where I want to be...

    I definitely need to break a leg and be confined to bed for a couple of weeks so I can finally launch myself deep deep deep into this ActionScript wizardry...

    Once again, thanks to all for contributing!

    Dubya

  13. #13
    Monkey Moderator Lexicon's Avatar
    Join Date
    Jul 2001
    Location
    UK
    Posts
    2,038
    no worries.

    I'm guessing PellePiano just misread/misunderstood the question rather than took the wrong route
    www.lexicon-design.co.uk
    If we aren't supposed to eat animals, then why are they made of meat?
    If Vegetarians like animals so much, why do they eat all their food?

  14. #14
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,045
    OK, i see why mine didnt work...i assumed _rotation started at 0, and just kept going up and up and up, it goes up to 180, then jumps to -180 and back to 0...my code worked for going from 0 rotation to 360*5 rotation...so 720 was 2 turns around and so on...Sorry about that! My mistake! Never ass-u-me...It makes an @$$ out of you and me!

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