iNET Interactive - Online Advertising Agency
          
SwishTalk.com
 

Go Back   SwishTalk.com > .:: THE HELP DESK ::. > » HTML and Backend Scripting

Reply
 
Thread Tools Display Modes
#1   [RESOLVED] Random SWF loads on Page Refresh??? Already searched...  

Name: 
Flash Noob
Status: Offline
Rank: Registered User
Posts: 12
Mood: What time is it?
Old 06-30-2004, 08:18 PM Reply With Quote


Well... I hate to ask something that's been drilled over and over, Especially for my first post.
I'm new to Swish and Flash in general... I'm also recently converted from FrontPage to DreamWeaver. I chose Swish over Macro-Flash becouse of it's simplicity (and my own).
My new job requires that I leave the "backyard" school of web-design and catch up with the rest of the world. WYSIWYG web-design with FP made me a slacker and now... I've got a lot of catching up to do.

Making customers happy is easy, has been for the last 8 yrs.
Making Programmers happy is turning out to be quite another story.

I'm an old hat at the forums stuff, so I've searched this forum and the web in general before posting... everything I pulled up in the forum search points to dead links or missing tutorials. :blink:
Everything I find on the web is over my head or AdManager junk.

So I'm going to ask what's been asked so many times already and hope that through the "FLAMES" I can find the answer I'm looking for.


QUESTION: How can I get an page to load a random .swf files each time the page is loaded or refreshed?

I'm using a small piece of Swish... just text with a few smooth effects. Very subtle. Sort of a banner.... but not really (IMHO).
Each piece is the same size and effects, just different text.
I've tried doing this within Swish... but I'm still figuring out sprites and I don't think (from what I've read here) that this will truly accomplish a random action anyway. The same routine will run at the bottom of every page on the site... so the page load obviously would reset any sort of tricky, single file solutions I would try... not to mention file size then becomes an issue.

I'm also told that while Java solutions are always an option... PHP is the desired way to go (my picky programmers), once they get the server setup anyway.



Well... that's allot for post #1, so I'll leave you with this: :spammer:
The forums are great, have already been a big help and a great resource... along with all of SwishTalk, so THANKS to all of you out there that have made this place such a great resource for us n00bs. :wave:
 
View Public Profile Send a private message to Flash Noob Visit Flash Noob's homepage! Find all posts by Flash Noob Add Flash Noob to Your Buddy List
#2    

Name: 
filter
Status: Offline
Rank: Honored Member
Posts: 1,882
Old 06-30-2004, 08:43 PM Reply With Quote


Welcome to the forums.

I think the best way would be to learn how to load external swf files. Once you have that understood, learn about random numbers in swish. It can be done fairly easy.

You can check out swish-tutorials.com for examples of how to load external swf files.
To learn about random numbers use the help file that comes with swish and do a search for random.
 
View Public Profile Find all posts by filter Add filter to Your Buddy List
#3    

Name: 
Flash Noob
Status: Offline
Rank: Registered User
Posts: 12
Mood: What time is it?
Old 07-01-2004, 02:11 AM Reply With Quote


So I can do all of this within Swish and still keep the file size down?
Alrighty... thanks for the pointers, I'll be checking them out.

FYI... Swish-Tutorials led me here, so I'll have to go dig around there again.


Thanks. :huh:
__________________
Sometimes your the windshield... sometimes your the BUG!!! :ph34r:
 
View Public Profile Send a private message to Flash Noob Visit Flash Noob's homepage! Find all posts by Flash Noob Add Flash Noob to Your Buddy List
#4    
 
mobosof's Avatar

Name: 
mobosof
Status: Offline
Rank: Super Moderator
Posts: 15,918
Mood: wow warlock will...grrrr
Old 07-01-2004, 02:15 AM Reply With Quote


 
View Public Profile Send a private message to mobosof Visit mobosof's homepage! Find all posts by mobosof Add mobosof to Your Buddy List
#5    
 
grumblemarc's Avatar

Name: 
grumblemarc
Status: Offline
Rank: Registered User
Posts: 67
Old 07-04-2004, 12:13 AM Reply With Quote


Well suppose you have an entry page that has a small SWF playing that you want to be different each time you revisit/refresh the page? I have a javascript that says it will do just that.

Place the script below anywhere after the <BODY> Tag.

<script language="JavaScript">

// Generate a Random Number
var randomnumber = Math.round(Math.random()*3);

// Select a movie and execute the corresponding function
if (randomnumber == 1)

{movie1();}

else if (randomnumber == 2)

{movie2();}

else {movie3();}

//Functions to write out the correct flash movie resource.

function movie1(){
document.write("<object classid=\"clsid27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" width=\"300\" height=\"200\"><param name=movie value=\"movie1.swf\"><param name=quality value=high><embed src=\"movie1.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"300\" height=\"200\"></embed></object>")
}

function movie2(){
document.write("<object classid=\"clsid27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" width=\"300\" height=\"200\"><param name=movie value=\"movie2.swf\"><param name=quality value=high><embed src=\"movie2.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"300\" height=\"200\"></embed></object>")
}

function movie3(){
document.write("<object classid=\"clsid27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0\" width=\"300\" height=\"200\"><param name=movie value=\"movie3.swf\"><param name=quality value=high><embed src=\"movie3.swf\" quality=high pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"300\" height=\"200\"></embed></object>")
}

</script>


Here is another.

<html>
<head>
<title>Random Flash Movie</title>

<script language="JavaScript">


function ROSSWERKZ_movie(name,width,height){
this.name=name; this.width=width; this.height=height;
}
var ROSSWERKZ_movieList = new Array();
KW_movieList[ROSSWERKZ_movieList.length] = new ROSSWERKZ_movie('button1.swf','100','22')
KW_movieList[ROSSWERKZ_movieList.length] = new ROSSWERKZ_movie('button2.swf','100','22')
KW_movieList[ROSSWERKZ_movieList.length] = new ROSSWERKZ_movie('button3.swf','100','22')
KW_movieList[ROSSWERKZ_movieList.length] = new ROSSWERKZ_movie('button4.swf','100','22')

j=parseInt(Math.random()*ROSSWERKZ_movieList.lengt h)
j=isNaN(j)?0:j;
document.write('<object classid="clsid27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,2,0" width="'+KW_movieList[j].width+'" height="'+KW_movieList[j].height+'">
<param name=movie value="'+KW_movieList[j].name+'">
<param name=quality value=high>
<param name="BASE" value=".">
<param name="BGCOLOR" value="white">
<embed src="'+KW_movieList[j].name+'" base="." quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="'+KW_movieList[j].width+'" height="'+KW_movieList[j].height+'" bgcolor="">
</embed>
</object>');

</script>

</body>
</html>


I have never been able to test these out. I had another that would load a mix of ANY type file. If I find it I'll post it. Hope it helps.
 
View Public Profile Send a private message to grumblemarc Visit grumblemarc's homepage! Find all posts by grumblemarc Add grumblemarc to Your Buddy List
#6    

Name: 
Flash Noob
Status: Offline
Rank: Registered User
Posts: 12
Mood: What time is it?
Old 07-05-2004, 02:48 PM Reply With Quote


filter: I went through swish-tutorials.com and picked up some great stuff, but couldn't find anything on loading external .SWF files. :wacko:
Did find loading .txt files... but nothing there specific to what I'm trying to accomplish. Have they changed since you saw what you suggested?

mobosof: Thanks for the link... can't beleive I missed that one. Must have been my search words. Having trouble getting it to fly... but having issue's with the test server too... so we'll have to see how it goes once they get everything ironed out.

grumblemarc: Thanks for the java. Programmers don't want me to keep java to a minimum, but I appreciate it and will see if I can get that to work once the server is working. I'm playing with the script now... just for fun and I may use that script on my own site if I can get it to fly. Thanks again.


My apologies for the delay on feedback. The assistance here is greatly appreciated. I'm not able to test any of these methods much right now... but I'm getting all the pages/methods ready for the server.
I'm not to sure if these programmers will be around much longer (they've been slackin') so limitations they request may be out the window soon enough.
So far I've got the .SWF solution, the JAVA solution and a PHP solution (programmers preferance) I found. I'd be happy to post the code I have for that... if anyone is interested, but like I said... I haven't been able to test anything live yet, so can't say if it will work or not.

Anyway... just thoguht I'd touch back and let you all know that I am checking out everything I'm getting here and appreciate the assistance.
__________________
Sometimes your the windshield... sometimes your the BUG!!! :ph34r:
 
View Public Profile Send a private message to Flash Noob Visit Flash Noob's homepage! Find all posts by Flash Noob Add Flash Noob to Your Buddy List
#7    
 
mobosof's Avatar

Name: 
mobosof
Status: Offline
Rank: Super Moderator
Posts: 15,918
Mood: wow warlock will...grrrr
Old 07-05-2004, 03:05 PM Reply With Quote


 
View Public Profile Send a private message to mobosof Visit mobosof's homepage! Find all posts by mobosof Add mobosof to Your Buddy List
#8    

Name: 
filter
Status: Offline
Rank: Honored Member
Posts: 1,882
Old 07-05-2004, 03:21 PM Reply With Quote


ok say you got like 10 movies you want to load named Movie1.swf to Movie10.swf
You can get a random number from 1 to 10 using randomrange.
randomrange(1,10);
problem is it will out put things like 7.09324
to correct that you use Math.round which will round off the number to the next whole number.
Math.round(randomrange(1,10));
now that's your random whole number for any number from 1 to 10.
you'll need to stick it in a variable to use it for loading an external swf movie

ranum = Math.round(randomrange(1,10));

now ranum is your randomnumber.

on to loading external swf files. you use loadMovie. Using load movie you will need a variable of a movie name or the movie name it's self.
loadMovie("Movie" add ranum add ".swf");
You can load external swf files one of two ways, into a level or into a sprite. To use a sprite, you just add in a new blank sprite. Set the anchor to the top left and move it to the spot where you'd like the top left of the external movie to appear. Then you just need to name it. I use names like placeholder or just place.
Now to get your movie to load into that sprite you just use
place.loadMovie("Movie" add ranum add ".swf");
So the whole code would be.

onLoad {
ranum = Math.round(randomrange(1,10));
place.loadMovie("Movie" add ranum add ".swf");
}

2 small lines of code that will load any external swf files randomly. Just make sure they are names like Movie1.swf to Movie10.swf
There are a lot of different ways to so the same thing but with a bit easier way to edit which swf files load.
 
View Public Profile Find all posts by filter Add filter to Your Buddy List
#9    

Name: 
rwedge
Status: Offline
Rank: Registered User
Posts: 75
Old 07-05-2004, 09:03 PM Reply With Quote


You can also use Math.floor to get a rounded number. In Javascript it is a better way to go when working with an array rather than Math.round, maybe this is true for Actionscript also. Keep in mind that typically scriptiing languages begin the count with 0 rather than 1.
/Bob
 
View Public Profile Send a private message to rwedge Find all posts by rwedge Add rwedge to Your Buddy List
#10    

Name: 
Flash Noob
Status: Offline
Rank: Registered User
Posts: 12
Mood: What time is it?
Old 07-15-2004, 03:02 PM Reply With Quote


OK everyone... here's the final solution that was used... PHP
The "Load Random File on Refresh" had to use an external PHP file to do the work, if there's an interest I can include that solution as well.

The easiest solution was the "Load File by Day" option.
Here are the relevant pieces for anyone interested...

Quote:
<param name="movie" value="swf_files/byday/<?php echo(date('l')); ?>.swf" />
<embed src="swf_files/byday/<?php echo(date('l')); ?>.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="450" height="25"></embed>
Of course the files in the directory: "swf_files/byday/" are named: "Monday.swf", "Tuesday.swf" and so forth.

In the end I was able to convince the "Boss" to go with the "Load Random File on Refresh" solution, but this "Load File by Day" option will be used as the site grows.

Again thanks to all for the help... the coes given have been put away for future referance. I hope that this can help someone else out.
__________________
Sometimes your the windshield... sometimes your the BUG!!! :ph34r:

Last edited by Flash Noob : 07-15-2004 at 03:06 PM.
 
View Public Profile Send a private message to Flash Noob Visit Flash Noob's homepage! Find all posts by Flash Noob Add Flash Noob to Your Buddy List
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump