Welcome, Guest
  • Author Topic: Delay in passing of variables to Flash  (Read 1514 times)

    Lord Helmet

    • Server what's that
    • *
    • Posts: 2
      • View Profile
    Delay in passing of variables to Flash
    « on: 07/30/02, 08:29 »
    L.S.,

    I have stumbled upon a problem in my ActionScript code. I am trying to pass a Session ID from my (dynamic) html page into a Flash movie. The idea is that the Flash movie can then use this Session ID to request database information through an XML script.

    Problem: The movie sometimes tries to authenticate with an empty Session ID.

    I use both a Javascript SetVariable and a Embed-tag method of passing the _root.sid variable to the Flash movie. For the time being I have inserted a five second wait at the start of the Flash movie (using an XML Perl script that sleeps for five seconds) but this proves an unstable solution.

    I figure it can't be hard to build a small loop testing wether the _root.sid variable exists, but so far my efforts have failed. Here is the construction I have come up with so far:

    Code: [Select]

    stop();
    if(_root.sid != null)
    {
     getData();  // contains the code to fetch XML data
    }
    else
    {
     gotoAndPlay(_currentframe-1);
    }


    For some reason the movie enters an endless loop this way, indicating that _root.sid never exists. Strange, since when I leave this part out sometimes it does exist at the moment getData() is executed and sometimes it doesn't, which indicates the method(s) of passing the variable is correct.

    Any help would be greatly appreciated.

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re:Delay in passing of variables to Flash
    « Reply #1 on: 07/30/02, 10:29 »
    After getData you need a scene, which is running until you received the data.

    If you have your serverscript waiting, you make it just worst.
    Aktualy the Flash has to wait until it is served by the server.
    This can take a view milliseconds or several seconds. Because you can never be shure how long the answer takes, you got to make a waiting loop.

    Say, you have a scene biginning in frame 10 with a Textfield saying:"Hold on, I'm busy."
    which fades out until frame 15.

    After your getVariablesNum -Statement you write: gotoAndPlay(10)
    In frame 15 you have a script saying:
    if (s_id eq 0)
    {
    gotoAndPlay(10);
    }
    else
    {
    gotoAndPlay(20); (if 20 is the frame where your actual movie starts)
    }
    Good luck
    Ron 8)
    happy flashing
    8)
    Ronald

    Lord Helmet

    • Server what's that
    • *
    • Posts: 2
      • View Profile
    Re:Delay in passing of variables to Flash
    « Reply #2 on: 07/30/02, 10:35 »

    After getData you need a scene, which is running until you received the data.
    If you have your serverscript waiting, you make it just worst.
    Aktualy the Flash has to wait until it is served by the server.
    This can take a view milliseconds or several seconds. Because you can never be shure how long the answer takes, you got to make a waiting loop.
    I am sorry, but you misunderstood my problem. The part after getData (with the XML transfers) is working perfectly and I have an object waiting for a response from the server before the movie continues to do its work.
    The problem lies with the fact that before the movie can fetch the XML data, it needs something (the session ID) to identify itself with and in passing that to the movie lies the problem, because at times the movie requests it's XML data before the session ID exists and therefor the server (side scripting) does not know what information to send to the movie.

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re:Delay in passing of variables to Flash
    « Reply #3 on: 07/30/02, 10:51 »
    If I got that right, it's somthing like a logon.
    Before the movie got the ID, it cannot request Info.

    Basicly its nothing else but again a loop.

    In your script you ask if SessionID is 0. This is not enough, because this test is only made once.
    Pack this Procedure in a scene and rerun it until succesfull.

    To prevent the movie looping forever, because the server ist not available, you can make a counter, which count the times the scene is run.
    That way you have a test in a loop with timout option.

    Allways cool  8)
    Ron
    happy flashing
    8)
    Ronald

    Ronald Wernecke

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 6203
      • View Profile
      • Professional Support
      • Email
    Re:Delay in passing of variables to Flash
    « Reply #4 on: 07/30/02, 10:53 »
    Just saw it:

    DONT put the request for the data into that loop  :) You know why. That poor server would be bombed by allways the same request and deliver you tons of session IDs.

    ;D
    happy flashing
    8)
    Ronald

    Musicman

    • Global Moderator
    • Systems Administrator
    • *****
    • Posts: 2685
      • View Profile
      • Email
    Re:Delay in passing of variables to Flash
    « Reply #5 on: 07/31/02, 14:40 »
    Hi,

    I know some people do not like cookies (yum yum) but if you use cookied sessions the session id is always available.
    Also, (since your html is dynamic) you could use <embed src=movie.swf?sid=12345>

    Musicman