Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




Loading Random Swf File



I am making a news scroller. And for this i have to load a random swf file containg the news. I want to load a random swf file every time a page is loaded from a specified folder and i want to add more news swf after some time. Is there a way that the parent flash movie can determine that how many swf files are there in a specified folder and can load a random file from that number of files. I dont want to use a text file in that way i have to update the text file each time i upload a new swf file.



FlashKit > Flash Help > Flash ActionScript
Posted on: 10-26-2003, 05:33 PM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Loading RANDOM XML File
I am trying to finish this project and it seems the client wants something new added every 15 minutes. I am now behind the ball on this one.

I have a client site, once you pick your geographic region, the viewer is supposed to be able to view a random cooking recipie. (XML file) There are different recipies for each region. I can get the list of recipies for each region, I can get the XML to load, but I can't get it to do so randomly.

Does anyone have any ideas for me?
By the by, I am using Player 9 and AS3.

Loading An External SWF File At Random
I want to load a random swf file on a layer called "illustration", and my initial code was the following:

loadMovie("swf/navcomp/bg_" add (random(4)+1) add ".swf", "illustration")

It keeps giving me errors... and I have no idea how to rewrite the code for it to work... any help would be much appreciated.

Loading Random .txt-file In Flash
dudes, I've gotta quite a tricky question
how do one loads a random .txt - file (like this one http://search.yahoo.com/search?p=loa...ab-web-t&x=wrt <- this html represents an excellent example) in flash variable?

once you use loadVars thingie it just shows your text as a kinda %EF%EE%E5%E1%E5%ED%FC - hexx codes. How do I get rid of them? is there any pre-defined way?

thanx.

Loading Random SWF File Problems
Code:
filename = ["header1.swf", "header2.swf", "header3.swf", "header4.swf", "header5.swf"];
path = "www.domain.com/images";
i = filename.length;
k = Math.floor(Math.random()*i);
loadMovie(path+filename[k], movieTarget);
That is the code that I am using for the container swf. I know the code works because I used it for static images and it worked fine. When I take a look and the HTML file, this is the error I get.

" A script in this movie is causing Macromedia FLash Player 7 to run slowly. If it continues to run, your computer may become unresponsive."

each of the header swf files are about 40k, and they each load AS from a single AS file. Do I need a preloader? Does anyone have any ideas?

Loading A Random .txt File Into A Dynamic Text Box
I have ten files called quote1.txt, quote2.txt, quote3.txt etc....

What code would I need to randomly load one of these files into a dynamic text box in my movie called 'quotetext'?

Any help is much appreciated

[CS3] Loading A Random Word From Text File
I need some help with loading a random word from a text file. I have a text file that has 250 words in it and reads like this.

Code:
word0=ace
word1=act
word2=ape
...
I need to either load every word into and array or load a single random word from the list, which ever is easiest.

I tried this code but to no avail.

Code:
var wordArray = new Array();
wordData = new LoadVars();
wordData.onLoad = function() {
randomNumber = Math.floor (Math.random() * 249);
trace(randomNumber);
currentWord = "word" + randomNumber;
randomWord = this.currentWord;
trace(randomWord);
}

wordData.load("lvl1_words.txt");
As well as this,

Code:
var wordArray = new Array();
wordData = new LoadVars();
wordData.onLoad = function() {
for(i=0; i<150; i++) {
currentWord = "word" + i;
wordArray[i] = this.currentWord
}
}

wordData.load("lvl1_words.txt");
All help is much appreciated, I can change the prefix of the words in lvl1_words.txt as I have written a C++ program that takes the words from an original file and appends a prefix.
Thanks.

Loading Flash Variables From Text File And Using In Random
In flash 5 I loaded variables from a text file and i can display them in dynamic text fields. (varibles are integers), but I can't do math with them or use in the Random() function. Flash recognises their values as 0. Does any one know how I could do this, thanks.

Loading Text File - Picking Random Vars
I'm trying to make a simple quiz for my students. Since I don't want to keep updating the FLA file it will load data from a text file. I hope to move up to MySQL in the future, but for now I am stuck with text files.

Basically there are three boxes on the screen. The top box has a word like "interesting", the bottom two boxes are choices such as "-er" and "more __ than". Students would pick the box that is correct for the top word, here it would be "more ___ than".

I can import data from a text file into one box, and I can shuffle things around randomly, but I am having trouble randomly picking something from the file. The file is in the standard format of:

&topWord0 = Interesting&
&topWord1 = Fast&

Eventually it will get much bigger and include other data such as the top word being a word and students have to choose Verb or Adj. It could also be a T/F question. For now I am trying to take baby steps since I am new to ActionScript (though I have done some ColdFusion and PHP).

Thanks

Random Background With Random Text File
I am trying to create a resizable flash file that will act as a background for my html/css website. Within the flash I want to have a script that randomly loads a jpg file from a specific folder on my server as well as a correlating txt file for that background. Here is an example of what I mean.

Say there is a movieclip named "background" and then a dynamic text area named "info" in the lower left-hand corner of the flash movie. I want a script to randomly load a jpg file (say 234.jpg) from a folder named "backgrounds" on the server. I also want it to load the correlating text file into the dynamic text area (234.txt) from a folder named "info". How would I do this and what would the script be?

NOTE: the names of the jpg and txt files would be 1.jpg, 1.txt, 2.jpg, 2.txt, etc.

Thank you for any help you can give!

-- K

Sequencial Imagem Loading To Random Loading
I've downloaded a free script that reads several JPG files and it makes a sequencial slideshow.

This is the function used:

ImageFader.prototype.loadXML = function (x) {
var _xml = new XML ();
_xml.ignoreWhite = true;
_xml.path = this;
_xml.load (x);
_xml.onLoad = function () {
for (var a = 0; a < this.firstChild.childNodes.length; a++) {
var _trans = this.firstChild.childNodes[a].attributes.TRANSITION;
var _pause = this.firstChild.attributes.PAUSE
var _img = this.firstChild.childNodes[a].firstChild.nodeValue;
this.path._dataProvider.push ({img:_img, transition:_trans, pause:_pause});
}
this.path.startFading ();
delete this;
};
};

My question is...
How to change that script to it loades random jpg from the xml in stead if loading img1, img2 from xml.

Anyone can help ? Thanks in advance

Random .swf File
I am looking to produce a banner that displays a different .swf file every time. I can guess there are two ways to do that

Upload each file to a directory and use html to do this

Do it in Flash 8 and then upload a single swf

Richard





























Edited: 09/18/2007 at 07:14:51 AM by richard222

Random Txt Out Of Txt File
Hi,

I want to get a random tekst out of a txt file,
(random txt1, txt2, txt3)

txt:

&txt1=bla
&txt2=bla
&txt3=bla


Code i have so far
loadText = new loadVars();
loadText.load("data.txt");
loadText.html = yes;
//creating the loadVarsText function
loadText.onLoad = function() {
txt.html = true;
txt.htmlText = this.txt1;
};

If anyone knows a good turorial for this, couldn't find anyting

Thanx

Problem W/ Sound Object File Loading Into A Holder File
Hi all,

I have a 4 mb file that I am loading into a main holder file. I am using loadmovienum to do this. In the 4mb file that i am loading in, i am using a sound object to control and play my audio.


Problem: when i publish the holder file, the 4 mb file loads just fine, but the audio doesn't play.

What Gives?

Load Random Txt File
Hi,
im building a new site. my client wants to have quotes from his clients displayed on there, but also wants to add more in the future... so i was thinking it would be best if he could just add the quotes to a txt file and flash would load them in whenever u goto the site.

However, i need it to work so that there's only 1 quote displayed at a time.

So is there a way of getting flash to select a quote at random from this 1 text file, and displaying it in say, a dynamic text box?

Many thanks and appreciation,

Place Random Pic From File?
I was wondering if it was possible to have a folder of pictures or symbols and have the movie import them randomly?

What I'm trying to do is make a screensaver that would take a random picture from a library folder and place that in the first frame of the movie each time its played. Is this possible? Can you understand my rambleling?

Thanks

Random Selections From An XML File
OK here goes. I have an XML file being loaded into flash(MX) see the sample below.


Code:
<tarot>
<card img="images/fool.jpg " name="The Fool">
<ExternalMeaning meaning=" Space before a decision or choice is made. A new cycle is about to begin that the seeker will enter inexperienced. New and endless possibilities. " />
<EsotericMeaning meaning=" The spirit of Aether. The limitless energy of spirit. Folly. Idea. " />
<Energys meaning=" Air " />
</card>
<card img="images/magician.jpg " name="The Magician">
<ExternalMeaning meaning=" Will and determination to see an idea or project though. Skill to organize and direct. Concentration and Control. Desires fulfulled by a strong will and the ability to utilize one's innate faculties to their fullest advantage. Originality and invention. " />
<EsotericMeaning meaning=" The magus of power. Creative focused attention. Will. Craft. " />
<Energys meaning=" Mercury " />
</card>


I can parse the XML file ok to show the picture and meanings for one card, I can use buttons to loop through all cards, but what I am trying to do is pick 3 random cards from the full XML file(78 cards)
and display them.

Can this be done?

Any help would be great!

Choosing A Random File
I am trying to write a triva game that will pull a random file from a folder, play that sound file and then never play it again. Anyone have any ideas?

Random Flash File?
I have 11 .swf files that I want to rotate randomly. They are all the exact same size. Does anybody have code that would work? I've seen a piece of code for random images, but I couldn't get it to work with .swf files (and wasn't so sure how to actually put it into the BODY of the HTML document so you can actually view it).

Any help would be appreciated

Random Background And Txt File
I am trying to create a resizable flash file that will act as a background for my html/css website. Within the flash I want to have a script that randomly loads a jpg file from a specific folder on my server as well as a correlating txt file for that background. Here is an example of what I mean.

Say there is a movieclip named "background" and then a dynamic text area named "info" in the lower left-hand corner of the flash movie. I want a script to randomly load a jpg file (say 234.jpg) from a folder named "backgrounds" on the server. I also want it to load the correlating text file into the dynamic text area (234.txt) from a folder named "info". How would I do this and what would the script be?

NOTE: the names of the jpg and txt files would be 1.jpg, 1.txt, 2.jpg, 2.txt, etc.

Thank you for any help you can give!

-- K

Load Random .swf File
I'm trying to build a Flash based application to display on a plasma screen in a corporate lobby. The goal of the application is to play one .exe file that loads random .swf files from a folder on the server. Can anyone share some sample code that shows how to load a random .swf file, play it, unload it, then load another one?

Any help would be greatly appreciated..

Using Random MC's In A Flash File
I have a little animation that comes in whenever a page is loading. As all the pages are linked to reduce movie size it's a little preloader to show people something is happening behind the scenes!

It's essentially a group of 5 animations that play in loops around another one, like dust clouds blowing around a main tornado. They are all individual mc's themselves inside a master mc which contains all the animation

To make this better is there a way I can call on these 'dust' mc's so that they are more random as after a while you can see the loop point. I could of course make a longer animation to cover slower internet connections but I think a random solution would be better!

So basically I want the 'tornado' mc to call each individual 'dust' mc at random intervals throughout its playback time until the next page loads.

Flash 8 Pro.

Random File References...
At runtime I'm pulling in two flv videos, one external swf, and xml data by way of a php proxy. All four of those files live in the same directory (as does the main flash app) called '/swf'.

My paths for loading are thus:

PHP Code:




flvPlayback.source = 'video1.flv';Loader.load(new URLRequest('/swf/mySwf.swf'));Loader.load(new URLRequest('/swf/proxy.php'));







So this is working but it's kind of crazy (and my integration guy thinks I can't copy-paste file paths). It seems like the Loader/URLRequest method is starting at the top of the domain while flvPlayback is referencing files from where the swf lives...can anyone explain whats going on here and why?

Load Random Jpg File
Hey,

Ive got a question about loading random jpg files based on a variable amount of jpg files.

For exemple:

Ive got 5 jpeg files with the filenames:
file1.jpg
file2.jpg
file3.jpg
file4.jpg
file5.jpg

so the amount of jpgs in this case will be 5, but it must be variabel, the number comes in from a php file wich counts the rows in a database table.. but this is not my problem, i can do this..
My problem comes in with the actionscript part
How can I load a random jpg from 1 till 5? (in this case)
Must be something like this but i dont exactly know how to do the correct actionscript code:

number = 5;
now generate random number

loadMovie("file+ the generated number here +.jpg", mcname);

Hope someone can help me with this, I know it must be simple but I'm noob

THanx!

Small Flash File Loading Into HTML - Weird Sporadic Loading
Hi,

I'm hoping someone can help...

I have a very small Flash file (less than 5k) loaded into a table cell of an HTML page .

On occasion (on Mac/IE) there is a flash of white appears in the table cell before the file starts. On other occasions only a portion of the file appears (while the rest of the cell is white). And at other times, none of the file appears (the table cell that it's in is appears as white).

The background of the flash file is orange (not white) so I guess that means that none of the Flash has loaded. Sometimes when I refresh the page, the problem resolves itself.

Does anyone know what the problem may be? Is there any sort of pre-loading JavaScript that would help, even though the file is very small to begin with?

Thanks for any help, I really appreciate it!

Loading A .swf File In A .swf File Works On Computer, Not On Site, Why?
I have a movie where at one point it plays a .swf movie in it, now on my computer it works perfect, but when i upload it, it just is blank during the time it should be playing... any ideas?

Loading An Array Of File Names From A Text File.
Basically I want to do the following.

Create an array of

Image[x] = "x.jpg"

from a text file where the images are listed as

x.jpg
y.jpg
z.jpg

I can't figure out how to load these in an array and I haven't been able to produce this from the closest examples I have found.

Any suggestions?

Loading Random Swf
Hey

I have created a series of external swf's and everytime somebody comes to my site a different movie must load.

Got some idea on how to do it but need some help

Cheers
ZieST

Loading Random .swf
Can anyone give me the script for a swf to load a random swf into it every time it's loaded/refreshed. Or tell me where I can find it.

thanks.

Random Loading
Vær hilset højtærede flashkit-medlemmer!
does anybody just happens to be in possession of a script that will load any one of a given number of movieclips by random?
it would be quit terrific and ease my Weltschmerz considerably
many greetings Mik

Loading A Random MC
Thanx to Mkit for help me withe following code:

_root.gotoAndPlay(name);
name = "F"+(random(6)+1);

Which allows my movie to jump to random spots using labels.

Now I need to modify it to load a random MC. I'm not to sure on how to naming structure goes.
How does it know to look for the MC in the library?
Do I use load movie to load it into a black MC on the stage?
Any help is apprectiated

Loading Random Swf
I've got 45 swf files from which I have to load 15 random files, but no file twice!

Any idea on what the best method is for picking 15 different numbers from a given 45 numbers?

Loading Random MCs
I have a few MCs that i want to randomly load...there my website sponsers ads. I would want it to change every so many seconds......How would i go about that?

Random Loading
Flash 5
I would like to load random bitmaps and swf's(or just swfs)
into a container movie. The random event would be on the
loading of the index page or swf.
Is there a standard random load scipt?
Would the code in the post above this one work?

Random Pic Loading
Alright. I want to have a random pic loaded up at the title of my SWF. How can i include the size of the .jpg in the preloader variables and make it load before it gets to the title?

the files are named something like

www.mysite.com/1.jpg
www.mysite.com/2.jpg
www.mysite.com/3.jpg
www.mysite.com/4.jpg
etc, etc.

I have had no problems simply loading the jpg onto the title screen, but the command to load it is AT the screen, so it sits there for a sec before the pic is loaded. I'm guessing i have to load it into the SWF at an earlier point, so it loads before it gets to the title, and then have it attach the already loaded pic.

that must've been a pain to read. i wonder how many times i said "load". anyway. thanks in advance.

Loading A Random Jpg
Ok on my stage I have a mc called "content_mc" which I want my jpg to be laoded into. My photos are stored in a folder called "main" and are name "1-10.jpg" Now I thought this script would work but it didn't.
content_mc.loadMovie("main/"+random(9)+1+".jpg");

Anyone have any idea on how I can get this to work?? Thanks in advance.

Random Loading
This one is a bit out of my expertise at the moment so I am hoping that someone can help.

I have a picture gallery that displays two pictures or .swf's at a time.

Is there anyway to get the main movie to randomly load two pictures from a choice of hundreds and to make sure it dosen't load the same picture twice in the same session OR day.

eg.

gallery one: loads two random pictures from a picture folder.
gallery two: loads two random pictures from a picture folder but remembers not to load the two pictures it has already loaded in gallery one.
gallery three: loads two random pictures from a picture folder but
remembers not to load the four pictures it has already loaded in gallerys one and two
etc..

Thanks in advance for any help you can give me. regards.

Random Loading?
Hi there, I am currently making an interactive flash where one must complete a certain amount of scenes/frames to complete this interactive flash.

However, I stumbled to a point where my AS knowledge has hit its dead end.

I currently have 5 files of .swf that I want to randomly load. My basic goal is to randomly load one of the 20 files in the parent flash movie, and once that movie is finished another random file would be chosen instead of the current flash, and once the next flash has been accomplished the movie will end with a great job! (7th) .swf

My files begin
1. intro <-parent flash
2. a.swf
3. b.swf
4. c.swf
5. d.swf
6. e.swf
7. Final Good job.swf

Basically for my first task, I want the movie to begin with
intro, once the button is prssed to assign a random movie:

_root.loadMovie("a.swf, b.swf, c.swf, d.swf, e.swf");

How do I randomize this?

thanks~

Loading Random PNG Using XML ...but
I am trying to do a random load of a transparent PNG images into my current flash movie. I figured out how to do it but the image always loads at the very top of the movie. Is there a way to tell the exact location of where I want the image to load. The only thing I can figure out is by using a button but the image still loads on the top.

Also was wondering by using XML and axtion script if it is possible to do a fade in.

Currently this is the script that I have

Action Script is as follows

Code:
imgXML = new XML();
imgXML.ignoreWhite = true;
imgXML.onLoad = function(ok){
if (ok){
images = imgXML.childNodes[0];
random_img_num = Math.round(Math.random()*(images.childNodes.length-1));
curr_img = images.childNodes[random_img_num];
trace(curr_img);
loadMovieNum(curr_img.attributes.src, 1);
}
};
imgXML.load("images.xml");


Here is my XML code

Code:
<?xml version="1.0" ?>
<images>
<image src="img/01.jpg" />
<image src="img/02.jpg" />
<image src="img/03.jpg" />
<image src="img/04.jpg" />
<image src="img/05.jpg" />
</images>

Loading Random Mc's
I've run into a problem...
I have 10 empty mc's on the stage, and I want to load 10 images into them randomly each time the movie is run, so they are in a different order everytime. I've created my array, but am now stuck...
How would be the best way to have each mc load an image, but without duplicating either so all 10 are there?
Thanks

Loading Random Mc
I feel like I am missing something ridiculously stupid here. I have been tearing my hair out for hours trying to figure out how to do something as simple as load a random mc in AS3.
the linkage names are set as Pic1, Pic2, etc all with a base class of MovieClip.
Here is the code of my movie.
var _pic1:Pic1 = new Pic1();
var _pic2:Pic2 = new Pic2();
var _pic3:Pic3 = new Pic3();
var _pic4:Pic4 = new Pic4();
var _pic5:Pic5 = new Pic5();
var _pic6:Pic6 = new Pic6();
var _pic7:Pic7 = new Pic7();
var newImage:*;

var allImages:Array = new Array();
allImages = ["_pic1", "_pic2", "_pic3", "_pic4", "_pic5", "_pic6", "_pic7"];


function findRandomimage (event:MouseEvent):void
{
newImage = allImages[Math.floor(Math.random() * allImages.length)]
trace(newImage)
addChild(newImage)
}

button.addEventListener (MouseEvent.CLICK, findRandomimage)

And here is the error message I am getting.

TypeError: Error #1034: Type Coercion failed: cannot convert "_pic4" to flash.display.DisplayObject.
at test_fla::MainTimeline/findRandomimage()
I would really appreciate any help. I've been trying to figure out this as3 stuff and still feel like an idiot
Thank you thank you,
bagooshi

Random Loading Plz Help
hai to all

i did 5 swf's and one main movie. i had loaded the small swf's into main movie. everthing is right and loading.

what i want is -> assume no. 4th swf is loaded in main swf againthe same 4th is loading i want a random one should load which is the not previously loaded. it should again do random and load the corresponding swf

it should not load twice the same one after the other same swf.

here is the code which i did here it is again loading the previous one plz help
var x:Number = random(5);
swf = "swf/" add "main" add x add ".swf";
_roothold_mc.loadMovie(swf, 1);
var secs = 3;
var id = setInterval(function () {
clearInterval(id);
play();
}, secs*1000);
stop();

Random Loading Plz Help
hai to all

i did 5 swf's and one main movie. i had loaded the small swf's into main movie. everthing is right and loading.

what i want is -> assume no. 4th swf is loaded in main swf againthe same 4th is loading i want a random one should load which is the not previously loaded. it should again do random and load the corresponding swf

it should not load twice the same one after the other same swf.

here is the code which i did here it is again loading the previous one plz help
var x:Number = random(5);
swf = "swf/" add "main" add x add ".swf";
_roothold_mc.loadMovie(swf, 1);
var secs = 3;
var id = setInterval(function () {
clearInterval(id);
play();
}, secs*1000);
stop();

Help With Loading A Random Jpg
Like the actionscript tutorial Kirupa has for loading a random movie clip I need something similar that loads from a folder containing jpg images randomly when the page is loaded / refreshed. Help on this would be extremely appreciated. Nothing fancy like the masks he has on it, just something plain and simple.

Loading Random .swf's
So I followed the loading random movies tutorial which seems pretty straight forward and simple.
I also tweaked the create a photo gallery tutorial to my liking in order to produce a movie that does automatic fade-in/fade-out transitioning.
I then used the random loader to grab one of my five transitioning .swf's and spit them up on the screen.

So here's the problem...
My random loader loads one of the five .swf's but it only displays the first image of that movie and then just sits there. I can reload the page again and it will load a different .swf, but still it just sits there on the first image of the .swf that is loaded.

Any help or suggestions would be great...
thanks!!

Loading A Random Swf
I want to load a random swf from a group of 6. Basically from the intial page i want the user to press a button and this then displays one of the 6 swfs randomly.

I have saved my swf files as numbers 1-6.swf and saved them in a folder called movies. I need to firstly generate a random number between 1 and 6 and then load this corresponding swf file.

Can anyone help me please?

Random MC Loading
Hi All,

This is my first post here on Kirupa so forgive me for the n00b question!

I am working on a site for a friend of mind, and what he wants is that when the page loads it will load in say 25 random movie clips that I have created. These movie clips should be randomly spread out on the page. And then when you press F5 to reload the page then another say 25 random clips get loaded on to the stage???

I did see the Random movement tutorial on Kirupa but from what I gather it only loads in separate movie movies (.swf) files???

I hope this made sense, and I hope some one out there can help!

Thanks in advance people!

Rob

Help With Loading A Random Jpg
Like the actionscript tutorial Kirupa has for loading a random movie clip I need something similar that loads from a folder containing jpg images randomly when the page is loaded / refreshed. Help on this would be extremely appreciated. Nothing fancy like the masks he has on it, just something plain and simple.

Loading Random FLV
I am building a site where the client wants to have their video (converted to flv) to play as soon as the user loads the site.  I have one swf that is the shell for all the other parts of the site, and another swf that contians the video call.  How can I have flash pick an flv randomly (from 33 different streaming servers to balance the load) and still only have swf for the video?

I've seen examples of this using playlists where the AS picks a flv from the playlist and plays it as soon as the previous vid has ended, but we only want this video to play once and then fade out (with AS that is already written and working).

Thanks in advance!

Random Loading
Trying to create a quiz that loads questions from an external xml file. Would like to create X number of quizzes and have Flash load the quizzes at random.

Any help appreciated.

Richie

Copyright © 2005-08 www.BigResource.com, All rights reserved