Suppose all that happens initially in a client swf is a user clicks a hyperlink in a text object of the swf, so this requests a "page" from the server. In response the server just modifies that existing swf in the client browser, by for example (?) invoking public functions of it, and possibly passing in as parameters the name of image or data files which were also downloaded in response to the URL request. The crucial part is that all that can happen initially in the SWF is a URL "page" request. Is this commonly done and if so, how.
+2
A:
Clicking on an hyperlink in AS3 will trigger a TextEvent.LINK event, you can then listen to this event and in your function proceed to call the relevant service which in turn will send you a response which you can use to update your swf data.
Check the docs here for the TextEvent class http://www.adobe.com/livedocs/flash/9.0/ActionScriptLangRefV3/
Now, it all depends on what your link is, if it loads an XML ,then you can use the URLLoader class to load the XML data
private function init():void
{
var tf:TextField = new TextField();
tf.htmlText = "<a href='http://example.com/data.xml'>Update Data</a>";
tf.addEventListener(TextEvent.LINK, clickHandler);
addChild(tf);
}
private function clickHandler(e:TextEvent):void
{
trace(e.type); // link
trace(e.text); // http://example.com/data.xml
var loader:URLLoader = new URLLoader();
loader.addEventListener( Event.COMPLETE , dataLoaded );
loader.load( new URLRequest( e.text ) );
}
private function dataLoaded(event:Event):void
{
trace( event.target.data );// xml content
//from here you can then parse the XML & update your swf
}
PatrickS
2010-09-18 04:54:31
Thanks, yeah this should work - Is there anything special I have to do to keep the browser from trying to display the xml file as well, since that would be the default behavior.
Mark
2010-09-18 11:00:25
No, the browser will not display the xml. you're calling the url inside Flash , so the browser won't know about it , which also explains why the browser page won't refresh
PatrickS
2010-09-18 11:16:50
I'll find out in a minute I guess, but is it because you've added an evenListener for clickHandler that the page won't be displayed.
Mark
2010-09-18 11:36:22
This is a related question: The swf is in an html file, and when that html is loaded, it passes to the swf an xml file. That xml is referencing all sorts of other files in the same directory as the html and xml file on the server, and all these other files are accessible somehow. If I subsequently set up my swf as you have suggested to use urlloader to load another xml file from the server, will all the data files referenced by this other xml from the server also be accessible
Mark
2010-09-18 12:41:48
Just to attempt to answer my own question - These files in the xml are being loaded by the swf using SWFLoader, so I'm assuming they will still be accessible, namely because I already use urlloader to load the xml file, the name of which is passed to the swf by the html file. (The html file only passes the name of the xml file to the swf at startup, which uses urloader to load it, and then SWFLoader to load all the image and other files referenced by the xml, so that should all work the same if I load a new xml in response to a user click.
Mark
2010-09-18 12:47:18
yes, it should!
PatrickS
2010-09-18 12:53:57