dcsimg
A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: loading array variables from php to flash

  1. #1
    Senior Member
    Join Date
    Nov 2000
    Posts
    177
    I'm trying to use php to create an array within flash.

    in php here's the code:
    Code:
    $page = array ('news.php', 'none.php');
    
    for ($start=0; $start <= $result; $start++){
    	echo '&page['.$start.']='.$page[$start];
    }
    This will give the following output:

    &page[0]=news.php&page[1]=none.php

    Which can be read by flash. (using:
    Code:
     loadvariables("phpfile.php", "", "POST")
    ), The problem is that flash doesn't load this into an array. Do I have to declare the array before flash loads the php variables? - this would cause a minor inconvenience.

    All I really want to do is get flash to create an array with the filenames from the php file.

    Thanks for the help!

    Birdgenj



  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    have the php send the data as
    &page=news.php,none.php&total=2
    Use something like
    print "&page=" . implode(",", $page);

    Once the data has arrived (you have to wait here) make them an array like
    page = page.split(",")
    If your array is big and the movie starts running slowly, search the forums for "mysplit" or "prototype" and "split"; there is a replacement split function around that runs much faster than the original

    Musicman

  3. #3
    Senior Member
    Join Date
    Nov 2000
    Posts
    177
    Thanks a lot for your help!
    -- I always run into problems with combining a variable and a string to make a new variable name...
    Code:
    total = 10;
    for (start = 0; start>=total; start++){
       page+start = page[start];
    }
    Now the easiest thing in theory would be for the output of this to create 11 variables (i think) that would be: page0, page1, page2 etc. -- the problem is that I can't find the function in php or flash that would help me allow this to work. -- although I believe eval() is close (or is) the flash equivalent that I am looking for.

    Thanks Again!!
    Birdgenj

  4. #4
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    in array notation this is simply
    page[start] = _root["page"+start];
    but your loop had better look like
    for(start = 0 ; start < total ; start++)

    Musicman

  5. #5
    hey musicman, do you by chance have a .fla file that has the scripting for pulling out an array from a php database like this? or do you know where we can find one? I just can't seem to figure out the context of the little snippets that you post.

    thanks!
    -
    Jake

  6. #6
    Registered User
    Join Date
    Feb 2001
    Posts
    13,044
    Hi,

    sorry no fla....
    create textfile "pages.txt"
    &page0=abc&page1=def&page2=ghi&total=3
    Next, make movie
    frame 1:
    total = ""
    this.loadVariables("pages.txt");
    frame 2: no code, but perhaps a "busy" type animation
    frame 3: (keep busy animation on stage)
    if(total == "") gotoAndPlay(2)
    frame 4: (no more busy animation here)
    for(n = 0 ; n < Number(total) ; n++)
    pages[n] = this["page"+n]
    stop()
    trace(pages);

    When the movie stops, view variables - the pages[] array should be filled.

    Musicman

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