A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Equivalent of eval() actionscript function in php..

  1. #1

    Equivalent of eval() actionscript function in php..

    Well, here's some codes on how eval() actionscript function works:
    Code:
    piece3 = "dangerous";
    x = 3; 
    
    y = eval("piece" + x);
    trace(y);
    
    // Output: dangerous
    I'm just looking for an equivalent of this function in php, I'm trying to communicate arrays between php and flash. Unfortunately, flash doesn't load array variables? That's chad..

    if someone can help me

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

    you could consider comma (or pipe) separated list as well. Flash uses string.split to turn into an array, and php uses explode
    If you want to use seperate variables, in php you can do
    $varname = "piece$x";
    echo $$varname; // or perhaps echo ${$varname}

    Musicman

  3. #3
    always for rent
    Join Date
    Oct 2000
    Location
    Seattle
    Posts
    307
    if you are trying to load an array, just have PHP join the array with a special character. i typically use the tilde or the vertical line as these are hardly ever used. then, pass that string to flash and have flash split the string.
    the only way you will be able to pass variables to flash in the correct data type is with flash remoting. i don't believe that php supports this yet.

    jeremy

  4. #4
    thankyou. ${""} fixed my day

  5. #5
    Junior Member
    Join Date
    Dec 2001
    Posts
    11

    Hi...

    sinfiniti/Musicman, could you show me an example, or explain a little more?
    I have a multi user game.
    I have just a basic PHP -> w/r text -> Flash.
    Just need to enhance the PHP a bit to walk an array?

    User enters site. Flash loads from txt which shows how many games being played, and who are playing in each game. (Up to 4 players).

    So task at hand: How a player Starting or Joining or Quiting a game,
    creates, adds, or deletes an array (in the PHP/txt file.)

    Your help is greatly apreciated.
    "Think good, and it will be good."

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

    there is one problem: how does a player leave the game?
    If the game requires frequent interaction with the server, you would probably do omething similar to the "users online" at a forum
    Whenever data is received by the server, the file of current players would be read by the php script and rewritten. Every entry has a timestamp. Now, when nothing is received from a participant for a given amount of time, the system will assume it went away.
    So you have one script that rewrites the list
    Now, to read the list, there is another script that reads the file line by line and outputs flash vars.
    Of course, you can combine these - this is common for polled chat rooms. Since you ask the server for new message every few seconds, the requests can both update the participants' list and return it to the movie

    The actual way to do this would certainly depend on the total number of users and the frequency of requests

    Musicman

  7. #7
    Junior Member
    Join Date
    Dec 2001
    Posts
    11

    Thanks for the reply Musicman...

    I wouldn't need php to read it in when player first gets there.
    That, Flash can do on it's own with a simple loadvariables.
    When a player leaves however, it would need to walk the array of
    games, and remove that player.
    I wonder though, if I couldn't just read it into flash, process it,
    and spit it back out through php.

    Thanks again.
    "Think good, and it will be good."

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