Skip to main content
Known Participant
September 20, 2010
Answered

loading URL from XML?

  • September 20, 2010
  • 1 reply
  • 751 views

I have a movie clip in rectangle shape and need add link to that from XML.

How can I do that?

this my code


AS Code:

var xmlLoader:URLLoader = new URLLoader();

xmlLoader.load(new URLRequest("linkNewD2.xml"));

xmlLoader.addEventListener(Event.COMPLETE, displayHTML);

function displayHTML(e:Event):void {

                var xmlData:XML = new XML(e.target.data);

                var tURL:String = xmlData.Header1.option;

                targetURL(tURL);

}

function targetURL(event:String):void

{

var valURL:String = event;

myMc1.addEventListener(MouseEvent.CLICK, gotoHome);

function gotoHome(evt:MouseEvent):void

{

                var myURL:URLRequest = new URLRequest(URL(valURL));

                navigateToURL(myURL);

}

}

------------------------------------------------------------------------------------------------------------

XML Code:

<data>

<Header1>
<option>
http://www.google.com </option>
</Header1>

</data>

-------------------------------------------------------------------------------------------------------------

Please help me!

Thanks,

jafy

This topic has been closed for replies.
Correct answer Andrei1-bKoviI

This is not an error but warning. Warnings don't affect anything.

1 reply

Inspiring
September 20, 2010

First, never use nested functions - they bring in a lot of troubles.

Try this code (there are better ways but just to follow your initial approach). This code assumes that myMC1 is MovieClip:

var xmlLoader:URLLoader = new URLLoader();
// listeners should be added BEFORE load() is called
xmlLoader.addEventListener(Event.COMPLETE, displayHTML);
xmlLoader.load(new URLRequest("linkNewD2.xml"));


function displayHTML(e:Event):void {
     var xmlData:XML = new XML(e.target.data);
     targetURL(xmlData.Header1.option);
}

function targetURL(url:String):void
{
     myMc1.url = url;
     myMc1.addEventListener(MouseEvent.CLICK, gotoHome);
}

function gotoHome(e:MouseEvent):void
{
     navigateToURL(new URLRequest(MovieClip(e.currentTarget).url));
}

Jafy78Author
Known Participant
September 20, 2010

i am getting this error

Warning: 1058: Migration issue: The property url is no longer supported.  For more information, see LoaderInfo.url and the Loader class..

Thanks,

jafy

Andrei1-bKoviICorrect answer
Inspiring
September 20, 2010

This is not an error but warning. Warnings don't affect anything.