A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: sending Vars to Php

  1. #1
    Senior Member Boombanguk's Avatar
    Join Date
    Jun 2000
    Posts
    1,194

    sending Vars to Php

    Hi,

    Just want to be straight on this, If i want to send variables to a php script from flash, then in the php script, I have to access every single var that has been sent, as such...

    &_POST [ 'var1' ]

    so if I want to send a 1000 variables (for example) to a php script, I need a 1000 lines like the above?!?

    thanks
    boombanguk

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

    if you are sure you want all vars that are sent, you can often use loops based on
    for($_POST as $var => $value)

    The whole idea of requiring the access via $_POST etc. was to protect scripts from people who simulate the frontend (html form or flash movie) but add extra vars that the programmer did not plan to receive.
    A good compromise could be accepting variables matching certain naming conventions via an ereg()

    Musicman

  3. #3
    Senior Member Boombanguk's Avatar
    Join Date
    Jun 2000
    Posts
    1,194
    thanks, but something else i'm unsure about is the following, if I have an instance of a object, which is a class containing instances of other classes (in other words, an array of arrays), such as this..

    function ClassList(movename) {
    this.movename = movename;
    }

    function Class1(x, y, n, name) {
    this.x = x;
    this.y = y;
    this.n = n;
    this.name = name;
    this.List = new Array();
    this.List.push(new ClassList("move1"));
    this.List.push(new ClassList("move2"));
    this.List.push(new ClassList("move3"));

    }

    I then create an instance of Class1, and fill with data, then copy all across to a loadVars object, and then use sendandload to send to a php script..how does the php script receive the data??, or more to the point, how would the php script know the difference between the first variable called movename, and the 2nd instance of the variable movename ?? (if any of that made sense!)

    (and if theres no easy way for the php script to know the difference between the different instances of the variable with the same name, would it be better to convert it all to xml inside flash, and send it all as xml to the php script??)

    thanks
    phil.

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

    You cannot really send variables this way but would rather need to give them different names, like movename0, movename1, ...

    You might want to take a look at AMFPHP

    This way you can copy nested structures but do not have the overhead of xml packaging - the plash player sends and receives these data natively

    Musicman

  5. #5
    Senior Member Boombanguk's Avatar
    Join Date
    Jun 2000
    Posts
    1,194
    AMFPHP looks interesting, although I'm not sure what issues there would be using it with a commercial project.

    but what did you mean by "overhead of xml packaging" ?? did you just mean all the hassle of reformating the data?

    boombanguk

  6. #6
    Member
    Join Date
    Aug 2003
    Posts
    30
    look at PHPObject .

    Opensource flash remoting, pretty cool.

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

    sending data as xml may double the data size, so if you are sending thousands of items, it is certainly worth a look.
    External methods for serializing data add to the size of your movie and may slow down things a bit

    Musicman

  8. #8
    Senior Member Boombanguk's Avatar
    Join Date
    Jun 2000
    Posts
    1,194
    I wouldn't say 1000s, but maybe.....the real issue for me in that case, would be the time taken to download all those variables, can anyone give me some idea of the download time for 1000s of variables if in xml format??

    but it seems to me if you have arrays or arrays, or instances of classes and subclasses, the only real way to send all that data to a php script is with xml?? (without having to use AMFPHP, or PHPobject)

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

    given an object like that:
    Code:
    dataset = {
      x:1,
      y:1,
      name:'john',
      items:[
        {movename:'move1'},
        {movename:'move2'},
        {movename:'move3'}
      }
    };
    the xml representation could be
    Code:
    <dataset>
    <x>1</x>
    <y>1</y>
    <name>john</name>
    <items>
    <movename>move1</movename>
    <movename>move2</movename>
    <movename>move3</movename>
    </items>
    </dataset>
    The amf record would be somewhat near 120 bytes + header
    Basically every data item is prefixed with a one-byte type identifier, strings have two length bytes, and there are a few bytes for every array or object. Numbers always use 8 bytes.
    The most efficient way (but this is only available from server to browser, not the other way round) is swf packaging: strings have one zero terminator rather than two length bytes, only floats use 8 bytes, integers just take 4, and repeated names (like movename in your example) are transmitted only once.

    Musicman

  10. #10
    Senior Member Boombanguk's Avatar
    Join Date
    Jun 2000
    Posts
    1,194
    thanks, thats useful, XML looks like the way to go, I'll have a look around to see what I can find on the php reading the xml in though, as i'm not sure on that point, the other thing was originally I was planning to just read in all the variables from flash to php, and then write them all out to a .txt file, can I still do that with the xml data that has been read into the php script?, is it just a case of read it in, write it out?

    thanks
    boombanguk

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