Solved

Load Random Frame In Flash

Posted on 2009-04-08
6
588 Views
Last Modified: 2013-11-11
I am inexperienced with flash.  I am trying to insert code into a flash file that will make the file load on a random frame each time the page is loaded.  I have read another similar post and have tried using the code provided, unsuccessfully.  I wonder if I put the code in the wrong place or there might be something I am missing.

This is a very simple time line with 4 keyframes.  I just need the file to randomly "go to and stop" on any of those frames when users load my the web page.
var arr = new Array(2, 3, 4, 5);
var rnd = Math.floor(Math.random()*arr.length);
 
gotoAndStop(arr[rnd]); // Or gotoAndStop, depending on what you want to do.

Open in new window

0
Comment
Question by:dustin11_3
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 13

Expert Comment

by:crooksy88
ID: 24104401
Your code is correct (using Actionscript 2 anyway).
I've just created a new file with it and it works fine.

Have you placed this on the timelime? i.e. selected frame 1 and added this to the Actions panel?
0
 
LVL 13

Expert Comment

by:crooksy88
ID: 24104416
PS.

You can add trace commands to see what Flash is doing (whilst you are creating the file).

Amend your code like this:



var arr = new Array(2, 3, 4, 5);
trace("Array content: "+arr);
 
var rnd = Math.floor(Math.random()*arr.length);
trace("Array length: "+arr.length);
trace("Random Number: "+rnd);
 
gotoAndStop(arr[rnd]);
trace("Array number at random element: "+arr[rnd]);

Open in new window

0
 

Author Comment

by:dustin11_3
ID: 24109918
Hello!  Thanks for your quick reply.  I inserted the code into the actionscript code for the first frame in the timeline.  When I put in the tracing code I got output like this:
Array content: 1,2,3,4
Array length: 4
Random Number: 2
Array number at random element:3
....
And it seems to work, some what. But every time I hit refresh the same frame comes up.  Only on every five or ten refreshes does another image comes up.  But it is usually only two frames, never the other two.  Any idea why this would happen?

I have attached a sample of the file, with a few random pictures thrown in on the slides.  So you can see how I have it setup and perhaps offer some suggestion?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Expert Comment

by:crooksy88
ID: 24110445
No files attached?

Hit refresh?

Do you mean as you are viewing it in a browser window?

0
 

Author Comment

by:dustin11_3
ID: 24116322
Sorry, yes I mean if you load the flash in a browser window and hit refresh.  Also, it does the same thing each time I do a publish preview within flash.  

Sorry, I guess it will not let you attach .fla files.  

I have attached the only code I have in my timeline.  Again, there are 4 frames.  This code is in the first frame.
var arr = new Array(1, 2, 3, 4);
trace("Array content: "+arr);
 
var rnd = Math.floor(Math.random()*arr.length);
trace("Array length: "+arr.length);
trace("Random Number: "+rnd);
 
gotoAndStop(arr[rnd]);
trace("Array number at random element:"+arr[rnd]);

Open in new window

0
 
LVL 13

Accepted Solution

by:
crooksy88 earned 500 total points
ID: 24117947
If you change the filename from .fla to .txt you should be able to attach it.


0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adobe flash player fails to install 12 320
Dreamweaver FTP Access 12 95
how do I install adobe flash player on my ipad Air? 4 55
Adobe Flash player - Microsoft Edge 9 180
For those who don't know, Adobe Dreamweaver is a popular commercial web editor that enables you to design, build and manage complex websites. The editor is a WYSIWYG (What You See Is What You Get) web editor, which means that you can create your web…
Adobe Dreamweaver CS5 is a WYSIWYG web page editor that has advanced HTML, CSS, and Javascript rendering functionality and is probably the most well-known HTML editor available. Much of Dreamweaver's appeal centers around the Design View interfac…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question