-
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
--
-
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.
-
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?
-
-
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
-
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?
-
Hi,
one line in the php should have been:
print "&item$num=" . $matched[1};
Musicman
-
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};?
?>
-
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
-
--
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
--
-
menu looks tight. good.job
-
--
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.
-
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
-
--
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!
--
-
Hi,
i t looks more like this (tried with mozilla on linux):
Musicman
-
--
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|