A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Sending Numerous Variables from PHP to AS3

  1. #1
    Member
    Join Date
    Jan 2003
    Location
    Ontario
    Posts
    59

    Sending Numerous Variables from PHP to AS3

    I apologize if another thread already covers this, but my eyes are glazing over from reading so many forum posts, blog posts, etc. about this and nothing has quite made sense yet.

    What I am creating is something that will show a replay of a horse race that has already taken place in PHP and stored in MySQL. What I would like to do is have the data in PHP (which includes probably almost 100 variables in total, if not more) sent to my flash file to display the race accordingly. I have gotten the flash part to work properly with dummy variables, but now it's time to start sending some real data into it to be used.

    Everything just seems to be a bit over my head. I did some reading on AMFPHP but I am not very comfortable with OOP just yet and I haven't been able to find many examples that would be useful. I wouldn't mind trying the ExternalInterface, but I am not familiar with converting PHP variables into Javascript and most examples I have found are far more complex that I need and I'm having a hard time picking out what it is I do need.

    Flashvars seem like they would just cause more work than necessary, since everything would be passed as a string and most of the values are going to be numbers. I've also read a couple of things saying that use of as many variables as I would need isn't really appropriate for use with flashvars.

    On top of this, I have some multidimensional arrays being used and I'm not sure if that would cause any issues or not. I know Flash was a little picky about them during their initial creation for my testing purposes, so I'm not sure how they'll be sent over. Essentially, I have a loop in PHP that would grab each horse's time for each fraction of the race and store it in a variable like so:

    timedist[0][400]=26.7;
    timedist[0][800]=54.1;
    timedist[1][400]=27.1;
    tiemdist[1][800]=53.8;

    With 0/1 representing the number of the horse and the 400/800 (and on up to 3200) would represent the distance traveled so far in the race. Flash then takes the time and uses it accordingly for that horse in that segment of the race.

    I have also been debating about trying to use a text file for all of the vars, and pass the name of the text file (which would be different for each race) via flashvars, but I have also read that it would still treat the text file values as strings.

    I'm just really at a loss right now and don't know where I should try concentrating my efforts. Everything all at once is just too overwhelming and I am relatively new to a lot of this.

    Thanks in advance for any help!

  2. #2
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349
    amfphp is a bit of a heavy framework, but allows you to call functions directly on the server without worrying about encoding the data or serializing it or whatever. you can call a function on a PHP server from within actionscript and the function can return an array and you don't have to write all the crazy code to sew up the data and move it around. it's amazingly powerful. i think it would be worth your time to do a tutorial and get started with it. you won't regret it.

    another approach would be to use JSON. as3corelib has some useful stuff like JSON encoding. PHP for its part has functions like json_encode which make it easier, but you still have to set up the urlloaders and stuff in actionscript.

    i would avoid trying to do this via flashvars.
    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

  3. #3
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,876
    have a look at http://www.sephiroth.it/test/unserializer/

    it will allow you to easily send/recieve arrays between php and flash
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  4. #4
    Member
    Join Date
    Jan 2003
    Location
    Ontario
    Posts
    59
    Thank you for the help guys, I really appreciate it.

    sneakyimp - do you happen to know of any good tutorials for AMFPHP?

    That looks really interesting silentweed, I'll have to check it out

  5. #5
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349
    Try googling. This is the first tutorial that shows up:
    http://www.flash-db.com/Tutorials/hello/flashamfphp.php
    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

  6. #6
    Member
    Join Date
    Jan 2003
    Location
    Ontario
    Posts
    59
    I've been googling but haven't been able to come up with anything somewhat useful yet. Either everything is in AS1/AS2 or it simply doesn't work. I'm just getting more and more confused reading all of these tutorials that don't even work for the most part. I'm so frustrated with this I'd be willing to pay someone to set something up for me. I have everything else done with this project for the most part, I just need these variables to get passed through

  7. #7
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349
    The tutorials on the amfphp website are not bad, if a little fast. Try "installing and testing part 1" -- it claims to show you how to set up amfphp in 7 minutes. Sephiroth, in addition to the php serializer class, has a whole section of tutorials on amfphp.

    Like I said before, amfphp is pretty heavy-duty, but once you learn it, you'll have a lot more power at your disposal.

    If you just want the variables to go through and want it done fast, look at the link silentweed posted. It doesn't get much faster than that.
    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

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