-
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
-
Bearded (M|G)od
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
-
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
-
Senior Member
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++;
}
}
-
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
-
Monkey Moderator
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?
-
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!
-
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!
-
Monkey Moderator
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?
-
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
-
Monkey Moderator
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?
-
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
-
Monkey Moderator
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?
-
Bearded (M|G)od
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|