 |
shpek
Young Devil

Registered: Jul 2002
Local time: 11:46 AM
Location: CT
Posts: 127
|
| Random image loader (loading images externally) | Post #1 |
Fellow Flashers,
I'm looking to assemble a random image generator that will:
1) load images externally
2) have a reload button that loads the next random image
I know this is probably pretty easy to assemble but i am juggle 3 other flash projects and cannot donate the time. If anyone has a .fla file or code I'd be in your debt.
thanks much!!!
Report this post to a moderator | IP: Logged
|
10-10-2005 06:24 PM |
|
|
|  |
 |
coop
Young Devil
Registered: Apr 2005
Local time: 04:46 PM
Location:
Posts: 184
|
I haven't tested it, but this should work
ActionScript:
pic_arr = ["images/1", "images/2", "images/3", "images/4", "images/5"];
one_btn.onRelease = function() {
ranNum = Math.floor(Math.random()*pic_arr.length);
holder_mc.loadMovie(pic_arr[ranNum]+".jpg");
};
|
Report this post to a moderator | IP: Logged
|
10-10-2005 06:44 PM |
|
|
|  |
 |
shpek
Young Devil

Registered: Jul 2002
Local time: 11:46 AM
Location: CT
Posts: 127
|
THANKS ALOT FOR SENDING THIS SO FAST.
I gave it a quick test but no go.... if you have a few spare minutes could you give it a try?
again, i really appreciate the assitance!!!
Report this post to a moderator | IP: Logged
|
10-10-2005 08:02 PM |
|
|
|  |
 |
shpek
Young Devil

Registered: Jul 2002
Local time: 11:46 AM
Location: CT
Posts: 127
|
ok this is great. I typod the name of the holder_mc, empty movie clip wrong (duh).
is this a TRUE random loader? seems that the same image can pop up more than once in a row.
but this is real good. thanks a TON!!!!!!!!!!
Report this post to a moderator | IP: Logged
|
10-10-2005 09:27 PM |
|
|
|  |
 |
ShapeShifter
<- [Staff Member] -> this.brainCells++;

Registered: Apr 2005
Local time: 05:46 PM
Location: Sweden
Posts: 2344
|
well.. it's not a problem to test if the newly generated image that is about to be loaded is the same or not.. and if it is then just go back one step and generate a new..
hope this makes sence 
__________________
>[ Rate Me 5! ]< >[ Rate Me 4! ]< >[ Rate Me 3! ]<
One who makes no mistakes never makes anything.
Report this post to a moderator | IP: Logged
|
10-11-2005 02:33 PM |
|
|
|  |
 |
coop
Young Devil
Registered: Apr 2005
Local time: 04:46 PM
Location:
Posts: 184
|
shpek,
It will be random, but it is a crude way of doing it.
Cos it is random, you could get the same number twice
You could to it so it picks random images but only picks them once, so the images wont repeat, if thats what you want.
Report this post to a moderator | IP: Logged
|
10-11-2005 02:50 PM |
|
|
|  |
 |
shpek
Young Devil

Registered: Jul 2002
Local time: 11:46 AM
Location: CT
Posts: 127
|
hey coop,
this will actually work but I was going to push it a little further so that each random load would not re-load or repeat the same image consecutively.
thanks again!
Report this post to a moderator | IP: Logged
|
10-11-2005 03:14 PM |
|
|
|  |
 |
shpek
Young Devil

Registered: Jul 2002
Local time: 11:46 AM
Location: CT
Posts: 127
|
Ah i just re-read it. i didint have my coffee yet
The way it is will actually work fine. I was wondering if I should build some type of prelaoder into it but I'm not sure its necessary and actually not sure how to build a preloader into an array like that so it will work dynamically with the random image loading though...
Report this post to a moderator | IP: Logged
|
10-11-2005 03:42 PM |
|
|
|  |
 |
ShapeShifter
<- [Staff Member] -> this.brainCells++;

Registered: Apr 2005
Local time: 05:46 PM
Location: Sweden
Posts: 2344
|
what's the problem? what code do you use to actually LOAD the image?
I'm guessing that there is a function that generates a name of the file from an array at random, then it sends this name to the load-function which in it's turn LOADS the file... so what would happen if you put a preloader-code inside that load-function?
__________________
>[ Rate Me 5! ]< >[ Rate Me 4! ]< >[ Rate Me 3! ]<
One who makes no mistakes never makes anything.
Report this post to a moderator | IP: Logged
|
10-11-2005 03:47 PM |
|
|
|  |
 |
kevint
Little Devil
Registered: Oct 2005
Local time: 04:46 PM
Location:
Posts: 31
|
quote: Originally posted by coop
shpek,
It will be random, but it is a crude way of doing it.
Cos it is random, you could get the same number twice
You could to it so it picks random images but only picks them once, so the images wont repeat, if thats what you want.
Actually, how would you do this coop?
I'm running my images in from a text file, so they can be edited out of flash. I'd like to have it not repeat the same image twice.
also. if you can answer this.
i want a link to be with the appropriate picture when called from the text file. is that possible? random image with appropriate link?
any help would be great.
thanks.
kt
Report this post to a moderator | IP: Logged
|
10-25-2005 06:05 PM |
|
|
|  |
 |
mickey
FlashDevil

Registered: Oct 2005
Local time: 04:46 PM
Location: Australia
Posts: 341
|
thus would be good 2;
if could set it so dont have to click the button? just be a random slideshow of images...
how???
Report this post to a moderator | IP: Logged
|
10-29-2005 03:19 AM |
|
|
|  |
 |
tivaelydoc
Little Devil

Registered: Nov 2005
Local time: 04:46 PM
Location:
Posts: 21
|
Is there anyway to attach a url to the images? Also, I wondering if you can display 8 images instead of 1?
Report this post to a moderator | IP: Logged
|
11-20-2005 12:40 AM |
|
|
|  |
 |
shpek
Young Devil

Registered: Jul 2002
Local time: 11:46 AM
Location: CT
Posts: 127
|
I'm pretty sure there is. I wonder if using an array would work. Each image would have an ID. That ID would be part of the array. Once an ID is established for each image I believe you could attach a URL to each image.
Report this post to a moderator | IP: Logged
|
11-21-2005 03:29 PM |
|
|
|  |
 |
tivaelydoc
Little Devil

Registered: Nov 2005
Local time: 04:46 PM
Location:
Posts: 21
|
That sounds like it would work, but I don't know the coding to do it...
Report this post to a moderator | IP: Logged
|
11-22-2005 06:56 AM |
|
|
|  |
 |
XemonerdX
veganXcodeXwarrior (StaffMember)

Registered: Apr 2002
Local time: 04:46 PM
Location: The Netherlands
Posts: 4818
|
One way would be to use an array of objects:
ActionScript:
picArr = [
{ image: "image/1.jpg", url: "http://www.flashdevils.com/"},
{ image: "image/2.jpg", url: "http://www.macromedia.com/"},
{ image: "image/3.jpg", url: "http://www.microsucks.com/"}
];
|
Then you can still use the same script to take a random item from the array and use the properties to get the correct values. Let's say:
ActionScript:
rnd = Math.floor(Math.random()*picArr.length);
item = picArr[rnd];
itemImage = item.image;
itemUrl = item.url;
// etc
|
__________________
.:: PoeticTerror.Com ::.
.:: FlashDevils ::.
.:: FlashFocus ::.
.:: GalaxyGoo ::.
.:: OrganicFlash ::.
Report this post to a moderator | IP: Logged
|
11-22-2005 08:43 AM |
|
|
|  |
 |
shpek
Young Devil

Registered: Jul 2002
Local time: 11:46 AM
Location: CT
Posts: 127
|
That's exactly what I was talking about.
Nice job!
Report this post to a moderator | IP: Logged
|
11-22-2005 02:50 PM |
|
|
|  |
 |
tivaelydoc
Little Devil

Registered: Nov 2005
Local time: 04:46 PM
Location:
Posts: 21
|
use this coding?:
ActionScript:
picArr = [
{ image: "image/1.jpg", url: "http://www.flashdevils.com/"},
{ image: "image/2.jpg", url: "http://www.macromedia.com/"},
{ image: "image/3.jpg", url: "http://www.microsucks.com/"}
];
one_btn.onRelease = function() {
ranNum = Math.floor(Math.random()*pic_arr.length);
holder_mc.loadMovie(pic_arr[ranNum]+".jpg");
};
|
or
ActionScript:
picArr = [
{ image: "image/1.jpg", url: "http://www.flashdevils.com/"},
{ image: "image/2.jpg", url: "http://www.macromedia.com/"},
{ image: "image/3.jpg", url: "http://www.microsucks.com/"}
];
one_btn.onRelease = function() {
ranNum = Math.floor(Math.random()*pic_arr.length);
holder_mc.loadMovie(pic_arr[ranNum]+".jpg");
rnd = Math.floor(Math.random()*picArr.length);
item = picArr[rnd];
itemImage = item.image;
itemUrl = item.url;
// etc
|
Also, I was wondering how you would display 8 pictures instead of 1?
Last edited by tivaelydoc on 11-24-2005 at 09:46 PM Why: update
Report this post to a moderator | IP: Logged
|
11-24-2005 03:14 AM |
|
|
|  |
 |
tivaelydoc
Little Devil

Registered: Nov 2005
Local time: 04:46 PM
Location:
Posts: 21
|
Can somebody show me how, because I tried a bunch of ways and none of them worked.
Report this post to a moderator | IP: Logged
|
11-27-2005 04:14 AM |
|
|
|  |
 |
ShapeShifter
<- [Staff Member] -> this.brainCells++;

Registered: Apr 2005
Local time: 05:46 PM
Location: Sweden
Posts: 2344
|
your second code looks like it should as far as I understand.. but what do you mean by 'displaying 8 pictures'? you want to have 8 holders and then each time a buttons is pressed all holders are updated and each and one of 'em loads a random picture?
__________________
>[ Rate Me 5! ]< >[ Rate Me 4! ]< >[ Rate Me 3! ]<
One who makes no mistakes never makes anything.
Report this post to a moderator | IP: Logged
|
11-27-2005 11:40 AM |
|
|
|  |
 |
tivaelydoc
Little Devil

Registered: Nov 2005
Local time: 04:46 PM
Location:
Posts: 21
|
Yes that's correct. Here's a pic to show what I want:
http://img176.imageshack.us/img176/...rtlayout0yz.jpg
I tried the last coding, but it gave me this message:
"Error opening URL "file:///C|/Documents%20and%20Settings/Cody/My%20Documents/.jpg""
I made a folder in my documents, that says image and when load the the original swf, it works, so what should I do?
Report this post to a moderator | IP: Logged
|
11-27-2005 08:26 PM |
|
|
|  |
 |
tivaelydoc
Little Devil

Registered: Nov 2005
Local time: 04:46 PM
Location:
Posts: 21
|
I put the trace command in there but now I get this error:
Error opening URL "file:///C|/Documents%20and%20Settings/Cody/My%20Documents/[object Object].jpg"
what should I do now?
Report this post to a moderator | IP: Logged
|
11-29-2005 12:55 AM |
|
|
|  |
 |
|  |
 |
ShapeShifter
<- [Staff Member] -> this.brainCells++;

Registered: Apr 2005
Local time: 05:46 PM
Location: Sweden
Posts: 2344
|
ActionScript:
holder_mc.loadMovie(picArr[ranNum]+".jpg");
|
here's his code.. I took it from a post above and modified it so it doesn't contain the error described earlier..
tivaelydoc, picArr[ranNum] is an OBJECT that contains a property called image.... so.. IF you want to access this property you should write
picArr[ranNum].image
OR!
as I can see you're creating a reference to the current Object in the variable item... and then you're storing the image-property in the variable itemImage by doing:
ActionScript:
item = picArr[rnd];
itemImage = item.image;
|
i don't know WHY you do that - I'm guessing you're gonna use those vars later somewhere coz you don't END your code in the first post, but why don't you move the loadMovie()-line AFTER declairing this itemImage-variable? then you ca simply do:
holder_mc.loadMovie(itemImage);
do you get what I mean?
__________________
>[ Rate Me 5! ]< >[ Rate Me 4! ]< >[ Rate Me 3! ]<
One who makes no mistakes never makes anything.
Report this post to a moderator | IP: Logged
|
11-29-2005 05:38 PM |
|
|
|  |
 |
tivaelydoc
Little Devil

Registered: Nov 2005
Local time: 04:46 PM
Location:
Posts: 21
|
Sweet I got it to work. Now if I have a site has that has the same front link, like: http://img.photobucket.com/albums/v727/tivaelydoc3/
and if address the images as 1, 2 , 3, etc, what coding should I change:
ActionScript:
picArr = [{image:"image/1.jpg", url:"http://www.flashdevils.com/"},
{image:"image/2.jpg", url:"http://www.macromedia.com/"},
{image:"image/3.jpg", url:"http://www.microsucks.com/"}];
one_btn.onRelease = function() {
ranNum = Math.floor(Math.random()*pic_arr.length);
item = picArr[rnd];
itemImage = item.image;
holder_mc.loadMovie(itemImage);
rnd = Math.floor(Math.random()*picArr.length);
itemUrl = item.url;
};
|
Report this post to a moderator | IP: Logged
|
12-01-2005 04:41 AM |
|
|
|  |
 |
ShapeShifter
<- [Staff Member] -> this.brainCells++;

Registered: Apr 2005
Local time: 05:46 PM
Location: Sweden
Posts: 2344
|
you shouldn't change anything.... the only thing you need to change in this code now is the path to the jpg and the link that's it! 
btw.. I couldn't get to that link of yours coz one need a password =|
__________________
>[ Rate Me 5! ]< >[ Rate Me 4! ]< >[ Rate Me 3! ]<
One who makes no mistakes never makes anything.
Report this post to a moderator | IP: Logged
|
12-01-2005 10:28 AM |
|
|
|  |
 |
tivaelydoc
Little Devil

Registered: Nov 2005
Local time: 04:46 PM
Location:
Posts: 21
|
well, as soon as i get some pics uploaded, its just going to be that adress and 1.jpg, 2.jpg, etc. So, instead of image/1.jpg I would the url with the 1.jpg at the end?
Report this post to a moderator | IP: Logged
|
12-01-2005 06:11 PM |
|
|
|  |
 |
ShapeShifter
<- [Staff Member] -> this.brainCells++;

Registered: Apr 2005
Local time: 05:46 PM
Location: Sweden
Posts: 2344
|
exactly... image/1.jpg means that there is a map in the same directory where your swf is called "images" and that 1.jpg is inside of that map... so if this is not the case in your folders make sure you insert correct path there 
__________________
>[ Rate Me 5! ]< >[ Rate Me 4! ]< >[ Rate Me 3! ]<
One who makes no mistakes never makes anything.
Report this post to a moderator | IP: Logged
|
12-03-2005 05:42 PM |
|
|
|  |
 |
| All times are GMT. The time now is 04:46 PM. |
 |
|
 |
|
|
|  |
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
|
|
|
|
|
< FlashDevils - Terms of use
>
Copyright, FlashDevils Community, 2002 - Flash Archive
|
|