A Flash Developer Resource Site

Page 1 of 2 12 LastLast
Results 1 to 20 of 24

Thread: Load images from txt file???

  1. #1
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488

    Load images from txt file???

    I must have slept through this class. I need to load some jpg's into a flash movie from a txt file. How do I do this?

    Thanx....

  2. #2
    Senior Member the_protectot's Avatar
    Join Date
    Jul 2003
    Posts
    401
    do you mean using the path to the image as a variable in the text file??

  3. #3
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Yes. I want to name the jpg in the text file. I'm trying to make it easier to change images in flash without opening it. Just change the txt file.

  4. #4
    Senior Member the_protectot's Avatar
    Join Date
    Jul 2003
    Posts
    401
    i think having &link=mypic.jpg in the the textfile, then loading the variables into the movie, then using loadMovie(link,targetMC); should do it...

  5. #5
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    OK, the &link=mypic.jpg was what I was initially looking for. So for more than one image it would look like this?

    &link=mypic.jpg&link1=mypic1.jpg&link2=mypic1.j pg

    Or should they be on separate lines?

    Now, my brain just knotted up. I understand how to load a txt file into a dynamic box, but what do I load this to, and then how do I target it? I think that's what I need to know. LOL

  6. #6
    Senior Member the_protectot's Avatar
    Join Date
    Jul 2003
    Posts
    401
    ok i getcha now..

    well in the text file, i usually don't use any spaces, so it's just a continious string of variables..

    then i load variables into _root and once the variables are loaded, i load the pics

    _root.onData = function(){
    loadMovie(_root.link, target);
    loadMovie(_root.link2, anotherTarget);
    }

    _root.loadVariables(myTextFile.txt);

    ...and that's it

  7. #7
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    I'm going to try and noodle my way thru this. I may be back.

    You don't happen to have an example fla do you?

  8. #8
    Senior Member the_protectot's Avatar
    Join Date
    Jul 2003
    Posts
    401
    No, I'm not home..but I'm sure you'll find it easy

  9. #9
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Your doing forum posts from WORK????

  10. #10
    pablo cruisin' hanratty21's Avatar
    Join Date
    Mar 2002
    Location
    on the lam
    Posts
    2,275
    Also, you can pu the links on different lines ( to make the text file look nicer) like so:
    link1=pic1.jpg
    &link2=pic2.jpg
    & etc.

    RH
    "Why does it hurt when I pee?" -- F. Zappa |

  11. #11
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    OK, I'm doing something wrong. I couldn't tell if the file was loaded, so I used this:

    _root.loadVarsText = new LoadVars();
    _root.loadVarsText.load("loadJpg.txt");
    _root.loadVarsText.onLoad = function(success) {
    if (success) {
    trace("Loaded");
    }
    };

    That traced as loaded. I used the one line and the separate lines in the txt file, like so:

    &link1=background0.jpg&link2=background1.jpg&link3 =background2.jpg&link4=background3.jpg

    I let this run 50 frames and added a stop and then this frame code:

    stop();
    _root.onData = function(){
    _root.mtClip.loadMovie("_root.link2");
    }

    Also tried it on a button:

    on(release){
    _root.onData = function(){
    _root.mtClip.loadMovie("_root.link2");
    }
    }

    I also tried it with the original code above. I know this is close, I'm just putting something in the wrong spot or forgetting something.

  12. #12
    Senior Member the_protectot's Avatar
    Join Date
    Jul 2003
    Posts
    401
    you don't use onData unless you used "LoadVariables" LoadVars comes with it's own onLoad function..which you used...so if you take the onData function away and just leave the loadMovie command...that should work...

    also you might want to loop the first couple of frames until onLoad is called, then, if the varibables are loaded successfully, then play the movie, the variables should thereafter be available for use.

  13. #13
    pablo cruisin' hanratty21's Avatar
    Join Date
    Mar 2002
    Location
    on the lam
    Posts
    2,275
    you could also put another variable at the end of your text file like:

    ...&status=done

    Then you could check for that variable in your loop to see if all of the variables are available to you.

    The vars will load in sequential order, so if status == done in your Flash movie, then everything esle will be there, as long as that is the last variable in the list.

    RH
    "Why does it hurt when I pee?" -- F. Zappa |

  14. #14
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    Tried that, still nothing. I get an error that it can't load the jpg. Maybe you can look at the fla and see whats wrong. I added the 50 frames to give it time to load, which ought to be enough, since it's only on my hard drive.
    Attached Files Attached Files

  15. #15
    Senior Member the_protectot's Avatar
    Join Date
    Jul 2003
    Posts
    401

    I'm home!

    Check this out.
    Attached Files Attached Files

  16. #16
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    OK, that cleared it up some. I'm thinking this is a waste of time though. If the jpg is there on the server it's just as easy to call it with loadMovie. Rather than update a text file, and the images, it would seem easier to just overwrite the images with new ones of the same name.

  17. #17
    Senior Member the_protectot's Avatar
    Join Date
    Jul 2003
    Posts
    401
    true, but if you're gonna be changing the number of images periodically, having a text file is one the only ways for flash to know how many images there are to load.

  18. #18
    FK's Geezer Mod Ask The Geezer's Avatar
    Join Date
    Jul 2002
    Location
    Out In The Pasture
    Posts
    20,488
    I see the point there, but I wanted to use the text file to hold the possibilities, and then load the various images from a button. Maybe I'm trying to use the wrong tool for the job.

  19. #19
    Actionscript Flotsam
    Join Date
    Feb 2003
    Posts
    33

    er, maybe just a syntax error?

    Maybe you already checked for this, or just mistyped it in your message, but...
    code:
    _root.mtClip.loadMovie("_root.link2");


    ...is going to look for an external file called _root.link2 rather than resolving the variable _root.link2 to the filename background1.jpg.

    You need to lose those quote marks.

  20. #20
    Banned
    Join Date
    Apr 2001
    Location
    Montréal, Québec.
    Posts
    25,397
    This is a 2 years old thread! Think Iaskwhy (now a moderator on FK!) has since solved his problem!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center