|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
loadmovie image from a txt file
I'm a bit puzzled on this.
I have a movieclip on the stage called mcImage and I want to load an image into it - the name of which I specify in a text file - when the clip is loaded. The actionscript I have on this layer is: loadVariablesNum("copy.txt", 0); loadMovie(picture, "mcImage"); The contents of the file copy.txt is: picture=Picture4.jpg When I test the movie I am expecting to see the image 'Picture4.jpg' loaded in the mcImage Movieclip. Instead I get a blank movie! If I have a look at the variables (List Variables) I get: Level #0: Variable _level0.$version = "WIN 6,0,21,0" Variable _level0.picture = "Picture4.jpg" Movie Clip: Target="_level0.mcImage" If I modify the script to: loadMovie("Picture4.jpg", "mcImage"); ...then the image displays on screen fine, but I don't want to have to specify the image name like this because I want to dynamically decide which image to display. I'm not sure what I'm doing wrong here. I'm very new to Flash and I'm experimenting with dynamic content. Can anyone explain why what I'm doing doesn't work? Last edited by Matt Phelps : December 2nd, 2003 at 06:34 PM. |
|
#2
|
|||
|
|||
|
Hi, I've been playing with sql lately. I had similar problems with that. This machine doesnt have flash installed or access to the sql db so I'll have to go from memory.
A couple of things that pop to mind straight away are: try: picture="Picture4.jpg" in the text file. It could be that easy. Do you have other things in the text file? if so is it like this: picture=Picture4.jpg &name=my fav pic &size=500x125 if so then you have to take the newline into account. if all of that still doesnt work. try this out: loadMovie(picture.substring(1, picture.length - 2), "mcImage"); That should chop the first and last characters off. An easy way to test all this out is to make a dynamic text box in root. Give it a variable name of picture. Then you can see exactly what is being loaded in. if you see quotes then you know that you've got to chop them off. My problem was to do with this. php was adding the quotes which made the resulting thumbnail not showup. forgot to mention if all of that doesnt work then stick in a new variable so you have: picture=Picture4.jpg&completed=true then in the frame which does loadmovie have completed = false; BEFORE the load movie part. Then do a check to make sure that completed == true before loading the movie. The problem could be to do with the file name not being completely read prior to you trying to load it into the target movie. Last edited by Tann San : December 2nd, 2003 at 07:03 PM. |
|
#3
|
|||
|
|||
|
I tried all you suggested and it didn't seem to make any difference. As I say - if I check the variables I think that the picture variable is loading correctly because I can see:
Variable _level0.picture = "Picture4.jpg" But I don't understand why this line doesn't work: loadMovie(picture, "mcImage"); Surely this is supposed to load what is in the picture variable - in this case "Picture4.jpg" - into that movie. How can I check it's doing this? I also should mention I don't really understand what all this 'level0' and 'root' stuff means. Could it be related? I seem to be loading the variables from Copy.txt into 'level0'. Is my mcImage movie not on level0 as well? Is that my problem? |
|
#4
|
|||
|
|||
|
Hi, try this out then:
loadMovie(_root.picture, _root.mcImage); _root is the main movie timeline, or the top most movie (the one that is already there when you make a new flash file). _root is level0. Each movie clip etc has a level number. Higher levels go ontop of lower levels. You can get a good idea of what I mean by using the target button in the AS panel. This will show the heirarchy of your movie timeline (as long as you have instance names on things). I can rant on for ages about this so lemme know! From your ealier post it appears that both the variable and the mcImage movie are in the root. |
|
#5
|
|||
|
|||
|
Thanks for helping, I do appreciate it but I must be doing something really stupid! I now have:
loadVariables("copy.txt", 0); loadMovie(_root.picture, _root.mcImage); If I understand correctly I've asked to load the variables in "copy.txt" into level 0 (or root) and then I'm asking it to load the variable 'picture' from root into the movieclip (which is sitting on the timeline at level zero in frame one) called mcImage. The actual result is still a blank movie. Again if I debug and check variables I get: Level #0: Variable _level0.$version = "WIN 6,0,21,0" Movie Clip: Target="_level0.mcImage" ![]() |
|
#6
|
|||
|
|||
|
Hi,
loadVariables("copy.txt", _root); loadMovie(_root.picture, _root.mcImage); This one changed from using a level with loadvars to using _root. If that doesnt work I'll be happy to take a look. ps. take the quotes out of the text file (if u put them in like i said too earlier, my bad!) |
|
#7
|
|||
|
|||
|
With the code above I have:
Level #0: Variable _level0.$version = "WIN 6,0,21,0" Variable _level0.picture = "Desk.jpg" Movie Clip: Target="_level0.mcImage" Looks like the variable picture has the right data in it but for some reason it won't upload it to the movieclip? I've attached the fla file for you to look at - AS is on layer 1. The text file (which lives in the same folder as the fla file) just has: picture=Desk.jpg and is called 'copy.txt'. I've added them all in the zip file. cheers ![]() |
|
#8
|
|||
|
|||
|
Hi, all done.
The problem was with the text file variable. Even though I tripple checked it didnt have a newline etc at the end flash still thought there was one. To fix it I capped the end with another variable. picture=pic2.jpg&done=true something like that anyways. we dont really care about done its just there to terminate the picture var. edit-> I removed dynamicimage.zip as I reached my attachment quota, ask and I will post it again. Last edited by Tann San : June 15th, 2004 at 04:27 AM. |
|
#9
|
|||
|
|||
|
Did you have to change anything in the FLA file? I'm using the one you uploaded but it seems the same? I changed my own copy.txt as you suggested, capped it with another variable but I still get nothing on the screen.
![]() |
|
#10
|
|||
|
|||
|
Hi, ok well I used the button you had in the library. I attached the code and it didnt work still. After a while I realised the capping thing. I moved loadVariables into the first frame so that it had a chance to complete before the button could be clicked. Sometimes with large data it can take a while to read in. I think if you use it before its finished you get incomplete data.
That could still be a problem here later on, but this should do for now. So back to the stuff: In _root -> frame 1: loadVariables("copy.txt", _root); That loads the text file variables into the root. on (release) { mcImage.loadMovie(picture, 0); } The button code changed slightly. What happens now is that the movie is loaded into mcImage level 0. Its basically the same thing. I'm not sure if changing it would have any effect because I did it before noticing the newline issue. Are you sure you got the image names right? you know originally you were saying Picture4.jpg and then the one you sent me was Desk.jpg? ummm...ok if your using my file how come it doesnt work? Does the swf file I sent work? Inside the text file: picture=Desk.jpg&done=true did you get the & sign in there? that seperates variables. |
|
#11
|
|||
|
|||
|
Image names are a bit difference but only because I was trying a different image. The zip file you uploaded seems to have the same files unmodified that I uploaded myself? Did you re-upload my original zip file or a new one?
|
|
#12
|
|||
|
|||
|
Hi, maybe I uploaded the wrong one. Didnt think I did but here it is again. I checked this one and it is definately the one I modded.
|
|
#13
|
|||
|
|||
|
Ah! Now it works! Thanks a million!
Is it possible to get it to load the image when the movieclip runs rather than have to have someone press a button? |
|
#14
|
|||
|