#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    2
    Rep Power
    0

    Dynamically display jpeg


    I want to display a jpeg in a Flash movie based on a value in a MIME-format text file.

    The text file is called "variables.txt", and contains the following:

    inum=image1.jpg;

    The following obviously works:

    _root.createEmptyMovieClip("imageHolder1",200);
    imageHolder1._x=0;
    imageHolder1._y=100;
    loadmovie("image1.jpg","ImageHolder1");

    But how do I replace the hard-coded image name with the value of the variable?

    Is it even possible?

    Thanks.
  2. #2
  3. No Profile Picture
    flash junkie
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    CO, USA
    Posts
    172
    Rep Power
    12
    hey, you'll want to load the values from the text file. And generally when you load variables, they need to be formatted like:

    &variable=value&variable2=value2...

    So, if you had a text file "variables.txt" with:

    &inum=image1.jpg

    in your flash movie, you sould say:
    PHP Code:
    //it's not actually php, obviously, but i just wanted to format the code
    myTextVars = new LoadVars();
    myTextVars.onLoad = function(success){
     if(
    success){
       
    _root.createEmptyMovieClip("imageHolder1",200);
       
    _root.imageHolder1._x=0;
       
    _root.imageHolder1._y=100;
       
    _root.imageHolder1.loadMovie(this.inum);
     } else {
       
    //trace error message
     
    }
    }
    myTextVars.load("variables.txt"); 
    You could also make an array of images in your text file, but there is no way to natively load in an array, you'd have to delimit your variables by something weird and then parse in flash:

    &images=image1|image2|image3|image4

    in flash you could just use the split method to make a flash native array. (flashImages = images.split("|"); )

    hope that helps,

    bret
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    2
    Rep Power
    0
    Bret,
    Works beautifully. Thanks for taking the time to reply.
    Ian

IMN logo majestic logo threadwatch logo seochat tools logo