Skip to main content
Jul 20, 2011 7:07 PM UTC
Question

Can I load xml file from a url on an iphone app?

I've seen a question similar to this, but the xml file was local. I need to do a URLRequest on an http address if it's possible.

I know the as3 is good as it works when I export to swf and chuck it live somewhere, but exported to ios it doesn't. No errors when compiling, so impossible to debug.

I have a crossdomain on the website that generates the xml to allow everything access, and I've both added Security.allowInsecureDomain("*");  and Security.allowDomain("*"); in the flash file. An the url is definitely correct and has http:// at the beginning.

I'm at a bit of a loss as to what to try next. So any suggestions are very welcome!

Thanks

Kev

This topic is closed to new replies. Start a new post to keep the conversation going.

4 replies

Inspiring
Jul 21, 2011 1:49 AM UTC

Can't you use a debug version on your device?

Are you trying to load a xml file or you query a php (for example) page that return an xml?

I did both, and both worked on iPad.

What are you doing with the xml once you received it? What happens on the iOS device?

Translate
Jul 21, 2011 8:44 AM UTC

Hello,

Thankyou for your response.

Could you suggest a debug version please? I'm new to ios so don't have a good set of tools setup for everything yet.

Eventually it will be a query, but this first test just involves loading an xml file hosted on a domain.

Good news at least to hear it can be done! Worth persevering then.

Here is the snippet of code for the xml. Once the xml is received it goes into a loop to extract some data and pops the second result into a text field. I tested the code online before sticking it into a new blank ios document. On the iphone, the text just doesn't appear in the text field. Doesn't crash or spaz out or anything.

Thanks

Translate
markc888
Inspiring
Jul 21, 2011 9:23 AM UTC

You can use the IOErrorEvent.IO_ERROR listener and trace for debugging to see if your xml is being received.

example...

var pageData:XML;

private function getInfo():void {

var url:String = "urlTo.xml";

var myXMLLoader:URLLoader = new URLLoader();

myXMLLoader.addEventListener(Event.COMPLETE, onLoaded, false, 0, true);

myXMLLoader.addEventListener(IOErrorEvent.IO_ERROR, errorXML, false, 0, true);

myXMLLoader.load(new URLRequest(url));

}

private function onLoaded(e:Event):void {

pageData = new XML(e.target.data);

pageData.ignoreWhitespace = true;

//for testing in Flash

trace("Data received: "+pageData);

//for testing to device

// example: textfieldOnStage.htmlText = pageData;

}

//handle xml load error

private function errorXML(e:Event):void {

trace("XML Error:"+ e);

// example: textfieldOnStage.htmlText = pageData;

}

Translate