Loading XML files in flash embed code

Discussion in 'Graphics & Multimedia' started by LanceT, Mar 3, 2007.

  1. #1
    Currently I am using this code in an actionscript file

    xml.load("file.xml");
    Code (markup):
    I want to make it so that I can load the XML file from my embed code instead of having it in my actionscript file.

    Basically I need something like

    
    <embed src=file.swf xml-file=file.xml></embed>
    
    Code (markup):
    - file.xml would be loaded the same way as it would be if i was using

    xml.load("file.xml");
    Code (markup):

    Is this possible?

    The reason I need this is because I am setting up a user system where each user would be loading a different XML file.
     
    LanceT, Mar 3, 2007 IP
  2. Mirage

    Mirage Active Member

    Messages:
    204
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Yes, this is very possible!

    What you want to use is the FlashVars mechanism introduced in Flash MX.

    You can read about it here:

    http://www.adobe.com/cfusion/knowle...40d32e2f0616&stateID=1+0+56598134&mode=simple

    In short, your embed and/or object tags include parameters that become variables in flash before Frame 1, so they are available immediately.

    Example of Object Tag:
    <PARAM NAME=FlashVars VALUE="foo=Hello%20World¶graph=first+line%0Dsecond+line">

    Example of Embed Tag:
    <EMBED src="display.swf" FlashVars="foo=Hello%20World¶graph=first+line%0Dsecond+line" ... (other parameters)></EMBED>

    Examples are straight from the page I referenced above. They include 'escaping' of special characters.

    Then you just access the vars within your flash script and you are ready to rock and roll (as I recall, the flash vars have global scope, so you can use them anywhere).

    I have used this before...very clean and easy.
     
    Mirage, Mar 4, 2007 IP