|
-
Actionscript: Random Image Rotation
Hi there...pretty new to flash and would like a simple question answering if poss...
Basically I have a small flash animation with 15 images, but I would like them randomized (IE: The first doesn,t always come first, the third doesn't always come third, etc)
Anyone able to help out?
Many thanks
Liam
-
put the animation into a movieClip, and then give that movieClip on the stage an instance name
(you do that in the property bar of flash- the same panel where you set your line style, font style, x/y positions ect. it the upper left input field I guess)
so for example if you gave the instance name "myMc" you can write the following code in the first frame of your flash movie on the stage (thus the main timeline, not the movieClip one!)
Code:
myMc.stop();
_root.onEnterFrame = function(){
myMc.gotoAndStop(random(myMc._framesloaded)+1);
}
wich should stop on each frame (fps) of your movie the MovieClip with the instance name "myMc" to a random frame of it´s possible length.
hope that helps
-
Hi renderhjs, thanks for the quick reply.
The 15 images I have are located in my actual flash document.
Do I place each image on one frame within the movie clip (Whilst naming the MC) etc and that's it?
-
yes I think so,- basicly your movie with it´s frames (you say images but I think you mean frames) is inside a movieClip. That is because with Actionscript it´s the best way accessing Animations in MovieClips.
give it a shot
-
renderhjs, I don't understand what I;m doing wrong here
I've uploaded it here: Random Images
Any chance you can show me where I'm going wrong?
Liam
-
ok here is what you did wrong:
you had:

but what I had in mind:

and this is the main stage, the main timeline also known as _root

but right now the frames change to fast so I changed the code to:
Code:
myMc.stop();
time = getTimer();
wait = 500;//1000ms = 1 second
_root.onEnterFrame = function(){
if (getTimer() > time+2000){
myMc.gotoAndStop(random(myMc._framesloaded)+1);
time = getTimer();
}
}
wich wait every 500 miliseconds (1/2 second) until he goes to a random frame change the part:
Code:
wait = 500;//1000ms = 1 second
to whatever time delay you want
-
-
Thanks for the prompt reply again, I'll give it a go and post back to tell you how I get on!
Liam
-
render, many thanks for your help.
All sorted.
Liam
-
I realize this thread is old but it's the best code I've been able to find to get a series of images to display randomly. However, there's one problem. They display randomly fine except for the first frame -- it is always first. I tried having the first frame empty, and then it worked except that there was a delay (as there should be) before subsequent random frames loaded. Any suggestions? (completely different code is okay too!) I'm using AS2.
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
|