Loading JPEGs from a textfile

Hi everybody. First post, so i’m a little imbarassed …
My need is easily described
In my movie I have :

  • MC_Menu (a movieclip with buttons inside)
  • MC_TextBoxes (a movieclips containing all my textboxes filled
    with data loaded from a textfile)

I need to have a space (probably a new movieclip) to be filled by a JPEG image which url is contained in the textfile.

In other words I’d like to have :

varTitle=Title Of The Section&VarText=All the text I need to write in the ‘lesson’&varImage1=“lesson1.jpg”

in my textfile …

Anyone can help ???

Thanks a lot…

Carlo

You will have to put in a different movieClip (called ‘container’ for now) and plop it on the stage. After the code that loads in your text, add:


_root.container.loadMovie("lesson1.jpg");

You could load in all the variables and direct them where to go, but that gets complicated - this is an easier solution for you.

BTW Welcome to the forum!!:slight_smile:

Thank you for your answer.
The purpouse of the application is giving some students a kind of ‘step by step’ lesson made with FlashMX.

So, for each part of the lessons I’ll have a few variables, as
Title, Text, Image1, Image2, Movie1, Movie2 and so on (they could virtually be as many as I need …).
My idea was to include all variables value in a text file.

For example, the images are linked to sites …
I’m looking for the chance to keep everything as a variable outside the Fla.
It could give me the ‘power’ to change everything so that my graphic interface is only a ‘graphic container’ for ALL my contents.

My fla is too big to be attached … :sigh:

Did I explain my question clearly ?

Carlo

Create a new, empty movieclip (CTRL+F8), drag it from the library (F11) to the stage, and give it the instance name image for example.

Now, place that movieclip inside another movieclip, which I’ll give the instance name container in this example. Once placed inside, place it where you want the image to load. You can easily do that by choosing Edit in Place when opening container, that way all the content will still be visible, so you can see where to put it.

Now, apply this code to container:

[AS]
onClipEvent(load){
lv = new loadVars();
lv.onLoad = function(success){
if (success){
image.loadMovie(this.varImage1)
} else {
trace(“Failed to load textfile”);
}
}
lv.load(“textfile.txt”)
}
[/AS]

… where varImage1 is the variable from the textfile that contains the path to the image. If this path is incorrect, the jpg will not load. And, make sure your jpgs aren’t progressive. Flash can’t handle progressive jpgs.

Thanks a lot, it was very clear.
Now, other 2 questions :

  1. Can I use that code to load any kind of file (JPEGS, SWFs, Video) ?

  2. The schema of my movie is :

SCENE1 contains MC_menu, MC_textboxes and MC_Container.

what I have to gain is that from a btn contained in MC_Menu I have to load data (text) into the textboxes of Mc_textboxes and the file into the MC_Image of MC_Container.

Actually on Button1, contained in MC_Menu, I have this code :

Actionscript :

_root.testi.gotoAndStop(2);
loadVariables("testo1.txt", "_root.testi");

where ‘testi’ is the instance name of the MC containing the textboxes.

So, if I want to load the image contained in my testo1.txt (called varImage1) in the image movieclip, contained in the container movieclip, the code should be something lik :

Actionscript :

onClipEvent(load){
lv = new loadVars();
lv.onLoad = function(success){
if (success){
_root.container.image.loadMovie(this.varImage1)
} else {
trace(“Failed to load textfile”);
}
}
lv.load(“textfile.txt”)
}

Or what ?

Thanks in advance .

Carlo

You want it to load when that button is clicked right ?

No, it should load the image as I left-click to load text …

Why the question ?

Left click on the button ?? This is why I’m confused:

what I have to gain is that from a btn contained in MC_Menu I have to load data (text) into the textboxes of Mc_textboxes and the file into the MC_Image of MC_Container.

So I suppose you want to load on left click on that button …

Yes that’s right …

Ah I see, you thought that I thought you wanted it to load when the button was rightclicked, because of this sentence:

You want it to load when that button is clicked right ?

I meant “right ?” in the way of “correct ?”. But anyways. Place this on your button:

[AS]
on(release){
_root.testi.gotoAndStop(2);
lv = new loadVars();
lv.onLoad = function(success){
if (success){
_root.textboxes.textF1.html = 1
_root.textboxes.textF2.html = 1
_root.container.image.loadMovie(this.varImage1)
_root.textboxes.textF1.htmlText = this.varTitle
_root.textboxes.textF2.htmlText = this.varText
} else {
trace(“Failed to load textfile”);
}
}
lv.load(“textfile.txt”)
}
[/AS]

To have it load the image to _root.container.image. It’s the same actually, only with an on handler instead of the onClipEvent handler. I am supposing there are several textfields contained within the movieclip with the instance name textboxes. I named two of those textfields textF1 and textF2 in this example. I’m not sure if your instance names are like MC_Container or just container, but you can always change it in the AS :slight_smile: I used varTitle and varText as vars from the textfile.

Thanks a lot for the last answer and sorry for my misunderstanding ‘right’ … :slight_smile: !!

I only get this problem : when I preview (CTRL+ENTER) my movie,
it returns me the message :

Error opening : and the name and path of the file …
I have checked the path and it’s allright (same dir as the swf) .
Even if I change the object to load ( I tried another jpg, or an swf file), the error is the same.

Can you help me checking this ?

Thanks …

That’s funny, if the image is there it should load … Are you absolutely sure the paths are correct ? We’re talking about the paths you specified in the textfile…

yes …
the image is :

varImage1=ciccio.jpg

with the & at the end of the varText=text …

Well yeah there’s nothing much I can do without viewing the folder, the fla and the textfile …

OK, you can find them here :

http://www.calibraclub.it/public/dynamicimage.zip

It will contain :

1- Main Fla
2- All the text files I use
3- The image

I will zip the whole folder, so it wll be as it is.

Make me know when you’ll find something… I think it will be the usual dummy error … eheheh

‘The page cannot be found’

Ok, sorry … I wrote a thing, then I’ve been on the phone talkin about other things, then posted on the site a file with another name … ooops…

the file is :

www.calibraclub.it/public/flash_prove.rar

It’s there …
thank you a lot !!!

The RAR appears to be empty :-\

I tried to dl from the site … it’s everything inside …
how can it be ?

ok,ok, now I put everything there : this is the path :

www.calibraclub.it/public/imaflash/

and the files are :

ciccio.jpg
introduzione.txt
testo1.txt
testo2.txt
text1.fla

hoping …

:slight_smile:

Carlo

Directory Listing Denied
This Virtual Directory does not allow contents to be listed.

:-\