Professional Web Applications Themes

Loading array from external file - Macromedia Flash Actionscript

Hi, I'm new to actionscript and experiencing a problem... I made ? photo gallery that I would like dynamic(not finished) but for the moment I have the following problem : My gallery works when the picture name array is written in the movie : myimg = ["photo1","photo2","photo3","photo4"]; I use this array to load the jpegs in the movie. I am trying to load this array from a text file but it won't work. I actualy tried the following code : in flash : box.loadvariables("info.txt"); in txt file : myimg = ["photo1","photo2","photo3","photo4"]; I dosen't work.... Would someone be kind enough to ...

  1. #1

    Default Loading array from external file

    Hi,

    I'm new to actionscript and experiencing a problem...

    I made ? photo gallery that I would like dynamic(not finished) but for the
    moment I have the following problem :

    My gallery works when the picture name array is written in the movie :

    myimg = ["photo1","photo2","photo3","photo4"];

    I use this array to load the jpegs in the movie.
    I am trying to load this array from a text file but it won't work.

    I actualy tried the following code :

    in flash : box.loadvariables("info.txt");

    in txt file : myimg = ["photo1","photo2","photo3","photo4"];

    I dosen't work....

    Would someone be kind enough to correct my mistakes...

    Thanks in advance.

    Seb


    scourtaud Guest

  2. #2

    Default Re: Loading array from external file

    textfile:

    &myimg=photo,photo2,photo3,photo4& // make sure there's no spaces around the
    comma's

    then in Flash use myFlashArray = myimg.split(",");

    Manual has more info on the string.split method. Bottomline is that
    variables from a textfile always arrive as a string in Flash. U use the
    String.split(delimiter) function to create an array out of it. Compare:

    myString="What a string this is";
    myArray = myString.spli(" ");
    trace(myArray);

    will output:
    What,a,string,this,is

    And obviously you have to wait for the variables to arrive before performing
    the split()

    John

    --
    ----------------------------------------------------------------------------
    -----------
    RESOURCES
    [url]http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash[/url]
    ----------------------------------------------------------------------------
    -----------
    TUTORIALS at
    [url]www.laiverd.com[/url]
    Flash & PHP Emailform
    Using textfiles in Flash
    ----------------------------------------------------------------------------
    -----------


    Laiverd.COM Guest

  3. #3

    Default Re: Loading array from external file

    Thank you for your help,

    It Works but not completely...

    It works great with a button :
    on (release) {
    .....
    }
    But I would like it to work with a clip :

    onClipEvent (load) {
    ....
    }
    End it seems impossible...
    The same code in the same clip gives "undefined" width the clip and the
    correct string with the button...

    Thank you again for your help...

    scourtaud Guest

  4. #4

    Default Re: Loading array from external file

    Maybe you should start 'studying' the loadVars Object which I feel is much
    easier to use, especially as it comes with the onLoad event.

    Try something like this

    onClipEvent (load) {
    // create a new loadVars object
    myVars = new LoadVars();
    // define what has to happen once the textfile has been loaded
    myVars.onLoad = function(success) {
    // if the file was successfully loaded
    if (success) {
    myFlashArray = this.myimg.split(",");
    // just a trace to check; skip in final code
    trace(myFlashArray);
    // skip the else partprobably in final code; or replace with something
    else
    } else {
    trace("file could not be loaded");
    }
    };
    // load the textfile
    myVars.load("info.txt");
    }

    Now remember that myFlashArray will belong to the timeline of the movieclip.
    If you want to access it from _root, use

    trace(clipInstancename.myFlashArray);

    John

    --
    ----------------------------------------------------------------------------
    -----------
    RESOURCES
    [url]http://groups.google.com/advanced_group_search?hl=en&as_ugroup=*flash[/url]
    ----------------------------------------------------------------------------
    -----------
    TUTORIALS at
    [url]www.laiverd.com[/url]
    Flash & PHP Emailform
    Using textfiles in Flash
    ----------------------------------------------------------------------------
    -----------


    Laiverd.COM Guest

Similar Threads

  1. Loading an array from an external file
    By SimonTheSwift in forum Macromedia Flash Data Integration
    Replies: 1
    Last Post: March 30th, 11:30 PM
  2. Loading w3d file from a external folder
    By mindylim in forum Macromedia Director 3D
    Replies: 7
    Last Post: February 24th, 11:00 AM
  3. MC Loading an External File
    By tyberius7 in forum Macromedia Flash Actionscript
    Replies: 1
    Last Post: March 4th, 12:14 PM
  4. Loading list component with an array using external variables
    By hoz webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: February 2nd, 02:36 AM
  5. Loading External data into an array
    By Dinghus webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 2
    Last Post: January 21st, 06:25 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139