A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: PHP Array in Flash -- winner gets the .FLA

  1. #1
    Member
    Join Date
    Aug 2003
    Location
    orange county, ca
    Posts
    42

    PHP Array in Flash -- winner gets the .FLA

    --

    I built a dynamic drop down menu in flash.

    Right now the menu looks to a predefined variable in flash, which holds an Array. That Array builds the drop down. This is what the variable and the Array look like (in flash).

    menu.MC4.z = new Array("sammy", "bendo", "kendo", "rendo", "wendo");

    Instead on having this Array predefined in flash, I would like to have PHP create it on the fly. Let me explain how…

    In my root directory I have a folder called “bob”, which has a bunch of “.swf” files in it.

    When I call the PHP script from flash I would like it to:
    • look in “/bob”
    • grab all the “.swf” files
    • strip the path and the dot extension ( /bob/thisfile.swf = thisfile )
    • build the new Array

    Lastly, in flash, I need to set “menu.MC4.z” equal to the new Array that PHP built.

    Here’s what the menu looks like.
    http://www.forij.com/flash/d.htm
    whoever gets it to work can have the .fla! (my gift to you)

    this is more of a PHP question but i havent found a good PHP forum. anyone know of a good one?

    mike

    --

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

    flash does not load arrays directly, and for your purposes adding a software that does so might be overkill.
    So, let php send
    &items=4&item0=sammy&item1=rondo....
    using code like
    Code:
    <?
    $dp = opendir("bob");
    $num = 0;
    while($f = readdir($dp))
        if(ereg('(.*)\.swf', $f, $matched))
        {    print "&item$num=$f";
             $num++;
        }
    closedir($dp);
    print "&items=$num";
    and flash call the php like
    Code:
    mylv = new LoadVars();
    mylv.onLoad = function()
    {   for(var j = 0 ; j < this.items ; j++)
            menu.MC4.x.push(this['item'+j]);
    };
    mylv.load('menu.php');
    Of course, building the menu must be called from than onload function too, otherwise the data wont be ready.

  3. #3
    Member
    Join Date
    Aug 2003
    Location
    orange county, ca
    Posts
    42
    So, PHP won’t send a complete Array to Flash?
    I need to create a loop in flash to build the new Array from the PHP info, right?

    The code above, it’s just setting up to be called, right? It isn’t actually creating the Array yet, is it? Do I still need to call the onLoad function to start the loop that builds that Array?

  4. #4
    Member
    Join Date
    Aug 2003
    Location
    orange county, ca
    Posts
    42
    by the way, thank you.

  5. #5
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    you would create an empty array before this happens
    menu.MC4.x = new Array();
    The onload function then fills the array with received data. It will be called when the call to the server finishes, and data is ready.

    BTW: a slight edit
    for(var j = 0 ; j < Number(this.items) ; j++)
    if you ever have more than ten entries in a menu.....

    Musicman

  6. #6
    Member
    Join Date
    Aug 2003
    Location
    orange county, ca
    Posts
    42
    This is great. We are almost there. One last thing…

    How can I strip the dot extension from the file name before I push it into the Array?

  7. #7
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    one line in the php should have been:
    print "&item$num=" . $matched[1};

    Musicman

  8. #8
    Member
    Join Date
    Aug 2003
    Location
    orange county, ca
    Posts
    42
    replace or add to? which one?

    PHP Code:
    <?
    $dp = opendir("bob");
    $num = 0;
    while($f = readdir($dp))
        if(ereg('(.*)\.swf', $f, $matched))
        {    print "&item$num=$f";<--- print "&item$num=" . $matched[1};?
             $num++;
        }
    closedir($dp);
    print "&items=$num";  <--- print "&item$num=" . $matched[1};?
    ?>

  9. #9
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Code:
    <?
     $dp = opendir("bob"); 
    $num = 0;
    while($f = readdir($dp))
          if(ereg('(.*)\.swf', $f, $matched))
          {     print "&item$num=". $natched[1]:
                $num++;
          }
    closedir($dp);
    print "&items=$num";
    Musicman

  10. #10
    Member
    Join Date
    Aug 2003
    Location
    orange county, ca
    Posts
    42
    --

    Thanks a million Musicman! Check it out

    http://www.forij.com/dropdone/

    Its yours if you want it. Just let me know where I can send it.

    mike

    --

  11. #11
    menu looks tight. good.job

  12. #12
    Member
    Join Date
    Aug 2003
    Location
    orange county, ca
    Posts
    42
    --

    just wanted to show you how its coming

    check it out

    http://www.forij.com/dropdone/

    --
    Last edited by mgulline; 06-24-2005 at 10:11 PM.

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

    what am I supposed to see - I just get a shiny ball but no piece of text, hand cursor, or anything else that could be considered the start of a menu.
    The movie is successfully calling menu.php and menu2.php, however

    Musicman

  14. #14
    Member
    Join Date
    Aug 2003
    Location
    orange county, ca
    Posts
    42
    --

    are you on a mac Musicman? i tried to show it to my buddy on his G5 and the menu wouldnt show up. you dont see it?

    looks like this




    anyone else having trouble viewing this on a mac?
    bah!

    --

  15. #15
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    i t looks more like this (tried with mozilla on linux):


    Musicman

  16. #16
    Member
    Join Date
    Aug 2003
    Location
    orange county, ca
    Posts
    42
    --

    that sucks!

    any ideas as to why it would work differently on different systems?

    --

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