The Ultrashock Ultra Bundle
  • Home
  • Community
  • Forum
  • Flash
  • ActionScript
  • Thread
  •  
  • Previous topic
  • Next topic
Sign up to post

Flash
 ActionScript

  • edub70 Author 
    • 1834 
    • 0 
    • 4 
    Random Display
    dbeechey

    Last reply Feb 20 2008, 02:09 PM

    by dbeechey

    Posted: Feb 19 2008, 05:59 PM

    by edub70

     

I have four Flash animations for the home page of my web site. Each time a user accesses the site, I need one of the four animations to randomly load.

I originally thought this would be done making four separate .swf’s (one for each animation), but I’ve heard it would be better to put all four in one .swf and use ActionScript to randomly generate where to start on the timeline, to randomly show one of the animations.

I’m new to ActionScript and would really appreciate any help with code I’ll need to achieve this. Thank you much!

  4 REPLIES
 
sims11tz
1  
sims11tz

I couldn’t really say if you should have them all in one swf or seperate…. probably depends on the filesize of said animations.  If they are large no need forcing your user’s to download all 4 just to see 1 of them.

But if you do put them all on the same timeline, you could use labels…. make lables like anim1, anim2, anim3, anim4

/*--- Taken from Flash Help Doc's ---*/
function randRange(min:Number, max:Number):Number {
    
var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
    return 
randomNum;
}

gotoAndPlay
("anim"+randRange(1,4)); 


Or if you want to load seperate .swf’s

/*--- Taken from Flash Help Doc's ---*/
function randRange(min:Number, max:Number):Number {
    
var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
    return 
randomNum;
}

loadMovie
("anim"+randRange(1,4)+".swf"); 
  • 19 February 2008 06:12 PM
  •  
edub70 Author 
2  
edub70

It worked! Thanks for pointing me in the right direction!

I ended up creating a 5-frame .swf. In the first fram I put this code…

Code:
function randRange(min:Number, max:Number):Number {
  var randomNum:Number = Math.floor(Math.random() * (max - min + 1)) + min;
  return randomNum;
}
for (var i = 0; i < 4; i++) {
  var n:Number = randRange(1, 4)
}

gotoAndPlay(“anim”+randRange(1,4));


In frames 2 through 5, I named them anim1 through anim4, and I did a loadMovie of each of the four animations.

Works great. Thanks again for your help.

-e

  • 19 February 2008 09:03 PM
  •  
edub70 Author 
3  
edub70

Check this out. Now that I have a proof of this posted on our FTP server, it’s not evenly distributing the four animations. In fact, it appears Firefox plays only three of them, and Explorer plays only three of them (but not the same three as Firefox). I’m completely baffled. Has anyone else run in to this problem or have any idea why it’s not generating a truely random selection? Thanks!

  • 20 February 2008 02:02 PM
  •  
dbeechey
4  
dbeechey

I’ve done this pretty successfully a few times using random swfs. That way only one swf loads - one site is www.rawhideco.com. If you want the code get back to me. regards, David.

  • 20 February 2008 02:09 PM
  •  
  •   Log in or join for free to make a comment.
 
Topic actions
  •  Share on Facebook
  •  Share on Twitter
Topic Categories
  •  Show All Topics
  •  Development
    •  Server Side
    •  Client Side
  •  Creative Software
    •  Web
    •  Video
    •  3D
    •  Illustrator
    •  Photoshop Battles
    •  Photoshop
  •  Design
    •  Typography
    •  Resources & Insight
    •  Checkpoint
  •  Career
    •  Copyright Matters
    •  Advice & issues
    •  Job Seekers
    •  Job Offers
  •  Flash
    •  UltraMath
    •  OOP
    •  Third Party Tools
    •  Open Source alternatives
    •  Data Communication
    •  Components
    •  Flex
    •  AIR
    •  Flash Lite
    •  Flash Professional
    •  Flash Newbie
    •  ActionScript
    •  XML
  •  Lounge
    •  Polls
    •  Random Chat
    •  Showcase And Critique
    •  BombShock Award Nominations
  •  Community Essentials
    •  BombShock Award Winners
    •  Tutorials
    •  Interviews
    •  News
    •  Bitmap tutorials
Popular Topics
  • Sort by: 
  • Activity
  • Views
  • Comments
  • Likes
Advertise with us
  • Your advertisement here!
  • loading
Ultrashock
  • Creative Assets
  • Community
  • Blog
  1. Home
  2. Forum
+/-
Creative Assets
  • Categories
  • Contributors
  • How to buy
Make Money
  • Commission Rates
  • Referral Program
  • Contributor Program
Community
  • Activity Feed
  • Forum
  • Profiles
About
  • Quick Tour
  • Our History
  • Banners & Logos
Support
  • Contact Ultrashock
  • Advertise with us
  • Legal Information
  •  Keep up to date
  • Flash 779  Flash
  • Audio 6,481  Audio
  • Vector 2,130  Vectors
  • Image 12,338  Images
  • Creative Assets 21,728  Assets
  • Profiles 282,751  Members
  • Topics 93,776  Topics
  • Blog 4  Blog
  • Facebook 1,679  Facebook
  • Twitter 1,163  Twitter
  • Join our FREE monthly newsletter!
  • Archive
  • Invalid email address. Please try again.
Subscribe
  • ©2012 Ultrashock LLC - All rights reserved
  • Terms of Use
  • Privacy Policy
  • Switch to dark theme
  • RSS Feeds
  • Top

©2012 Ultrashock LLC - All rights reserved

Printed on Sat, February 11, 2012 - 19:21:05