A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: split array with myArray.slice(start, end)

  1. #1
    "way too many questions"
    Join Date
    Feb 2001
    Posts
    312

    split array with myArray.slice(start, end)

    I have a text file containing:

    &img0=comment img0|images/image0.jpg&
    &img1=comment img1|images/image1.jpg&
    &img2=comment img2|images/image2.jpg&
    &img3=comment img3|images/image3.jpg&
    &img4=comment img4|images/image4.jpg&
    &img5=comment img5|images/image5.jpg&
    &TotalImages=6&

    With Flash I put the content of this text file into an array:

    slides = comment img1,images/image1.jpg,comment img2,images/image2.jpg,comment img3,images/image3.jpg,comment img4,images/image4.jpg,comment img5,images/image5.jpg,


    What I need is the following: I need the images/imageX.jpg in an array and the comments in ANOTHER array. I searched and found the myArray.slice option. But how do you use it in this situation? HELP, hahaha!


    So the result should be Array1 = images/image1.jpg etc.., Array2= comment img1 etc..
    \joris/
    Please check my site here or help me with ideas

    Celeron 1GigaHZ
    32MB tnt2 videocard
    256 SDRAM

  2. #2
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    hi,

    I don't know what you're trying to do, so I see no point in doing that.

    If you want to have two arrays with those values, the easiest way is creating them:
    code:

    var im_array = new Array();
    var comm_array = new Array();
    for (var i = 0; i < 6; i++) {
    im_array.push("comment image" + i);
    comm_array.push("image" + i + ".jpg");
    }
    trace(im_array);
    trace(comm_array);


    If this is what you want, loading all that data from the text file is useless.
    Code:
    &TotalImages=6&
    Is enough.

    And you use this variable in the for() loop:
    code:

    for (var i = 0; i < TotalImages; i++) {
    // code here
    }


    Make sure the variable has loaded before trying to use it.

  3. #3
    "way too many questions"
    Join Date
    Feb 2001
    Posts
    312
    yes but the comments can be really long. And they don't have to start with "comment".

    So i just want the first record in Array1 and the second record in Array2 and the third record in Array1 and the forth in Array2 etc..

    Or is this plain stupid?
    \joris/
    Please check my site here or help me with ideas

    Celeron 1GigaHZ
    32MB tnt2 videocard
    256 SDRAM

  4. #4
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    ok,

    The point is that you don't load data that you don't need.
    I think that you only need to load the comments, i.e., the pictures have default names.
    So, the text file can be something like:
    Code:
    &c1=this is the first comment&
    &c2=here goes the second comment&
    &c3=another comment... the third&
    ...
    &TotalImages=6&
    If the pictures have different names, maybe the best way is using xml.
    Text files are fine when you have simple data, but once it starts to get more complex, xml is both easier to create and deal with in flash.

  5. #5
    "way too many questions"
    Join Date
    Feb 2001
    Posts
    312
    Allright, I get your point. Maybe I should have explained it earlier.

    I want to randomly load images from a EXTERNAL directory ( that's why I put the image location in the textfile). I have a small textfield that should display the comment about the image.

    Right now it loads the images perfectly from the EXTERNAL directory. Because the content of the textfile is put in an array.

    The textfile only has the image locations+imageX in it, so no comments yet.

    The pictures have indeed default names.
    \joris/
    Please check my site here or help me with ideas

    Celeron 1GigaHZ
    32MB tnt2 videocard
    256 SDRAM

  6. #6
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    once again, if the images have default names and are in the same folder, you don't need to load text related to them

    take a look at this post

  7. #7
    "way too many questions"
    Join Date
    Feb 2001
    Posts
    312
    Whaaa I am a stupid ........Sorry I got it now...Thanks, it's working now, thanx a billion!
    \joris/
    Please check my site here or help me with ideas

    Celeron 1GigaHZ
    32MB tnt2 videocard
    256 SDRAM

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