View Full Version : Help with "For" statement..
Blinger1
16-07-2008, 11:08 AM
Okay, I am an alright Flash user, using Flash 8 (since we only have Flash 7 at school, I thought 8 was okay.)
Anyway, I have a problem with my code. All what is meant to happen is the line spins for 180 degrees only, but it keeps going.. forever!!
Here is my code:
onClipEvent (enterFrame) {
for(i=0; i<1; i++) {
this._rotation ++;
trace(i);
}
}
And here is the SWF (link (http://img410.imageshack.us/my.php?image=gayzie1.swf))
Protege
16-07-2008, 11:32 AM
Whats the trace saying?
Blinger1
16-07-2008, 11:37 AM
Oh yeah sorry, it just keeps saying "0"
Protege
16-07-2008, 11:40 AM
Oh yeah sorry, it just keeps saying "0"
Is the for, for a smooth rotation?
else if not ->
on (release) {
_root.mcobj._rotation += 180;
}
Blinger1
16-07-2008, 11:45 AM
I want it to go slowly the 180 degrees.. (it will soon be a random number)...
I have also tried a while statement, but that went too fast :(
Protege
16-07-2008, 11:56 AM
Basically the method your doing is rotating it on each frame enter, so its going to be infinite, so a for loop isn't how your going to do it on a frame enter, give me a few minutes and I'll come up with something.
Blinger1
16-07-2008, 11:57 AM
How about,
onClipEvent(load){
for(i=0; i<1; i++) {
this._rotation ++;
trace(i);
}
}
going to try that
edit: didn't work, the trace only says "0" :(
Protege
16-07-2008, 12:03 PM
This will work, add it to a button call the movieclip your rotating mcobj
on (release)
{
for ( var i = 0; i <= 180; i++ )
{
inter = setInterval( function () { _root.mcobj._rotation++; clearInterval( inter ); }, 25*i );
}
}
:)
http://www.disasterpiece.co.uk/flahabox.fla
Blinger1
16-07-2008, 12:08 PM
Okay that seemed to make it spin!
Now, how do I make it stop after it reaches 180 degrees?
Protege
16-07-2008, 12:17 PM
oo forgot :p
on (release)
{
rotation = 180;
for ( var i = 0; i <= 10; i++ )
{
var inter = setInterval( function () { if ( !rotation == 0 ) { rotation--; _root.mcobj._rotation+=1; clearInterval( inter );}} , 25*i );
}
}
Blinger1
16-07-2008, 12:30 PM
Thank you very much..
+rep, do you go on Habbo?
Protege
16-07-2008, 12:32 PM
Occasionally, and no problem ;) Needs a bit more work as it gets faster each time you press the button, I'll look into that later ;)
Blinger1
16-07-2008, 12:35 PM
nono, i didn't want it to get faste :P... It was going to be a "you are this cool" meter..
I'll donate you some rares next time i am on if you want :)
Protege
16-07-2008, 12:35 PM
Its alright, I'll see how I can make it to stop getting faster ;)
Protege
16-07-2008, 04:49 PM
Heres an update, its a easier method to rotate the objects
var objRotate;
var rotation;
function rotateObj ()
{
if ( ! rotation == 0 )
{
_root[objRotate]._rotation += 1;
rotation--;
rotating = true;
}
else
{
rotating = false;
clearInterval( interval );
}
}
function rotateObject ( degree, obj, speed )
{
if ( rotating === true )
{
// fail
}
else
{
rotation = degree;
objRotate = obj;
for ( var i = 0; i <= 180; i++ )
{
clearInterval( interval );
interval = setInterval( rotateObj, speed );
}
}
}
stop();Place that in the actionscript frame (root) and use this func to rotate any movieclip.
On a button :
on (release)
{
rotateObject( 90, "mcobj", -50 );
}In a script...
rotateObject( 90, "mcobj", -50 );
Syntax:
Pink -> Degree
Orange -> Instance name
Green -> Speed
Heres the (*.fla)
http://www.disasterpiece.co.uk/flash/rotateObj.fla
Heres an example (*.html)
http://www.disasterpiece.co.uk/flash/rotateObj.html
:D Any probs post.
Want to hide these adverts? Register an account for free!
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.