-
[AS3] Load dynamic XML
I have a picture slideshow and I can not figure out how to change the placement (X and Y) of my description text. Here is the code I have. Thank you!
PHP Code:
{
Main.url_array.push(node.firstChild.childNodes[i].attributes['url']);
Main.descriptions_array.push(node.firstChild.childNodes[i].attributes['description']);
}
-
Could you provide a bit more info. Xml of the data would be one thing. How is the data of x and y stored in the description.
-
Here is my .as file the loads my xml.
PHP Code:
package
{
import flash.display.MovieClip;
import flash.display.Loader;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.xml.*;
public class LoadingXML extends XMLDocument
{
private var _fla:MovieClip;
public function LoadingXML(fla:MovieClip)
{
_fla=fla;
loadXML();
}
private function loadXML():void
{
var loader:URLLoader=new URLLoader();
loader.addEventListener(Event.COMPLETE,completeHandler);
var request:URLRequest=new URLRequest('images.xml');
try
{
loader.load(request);
}
catch(error:Error)
{
trace('XML Could not load Document.');
}
}
private function completeHandler(event:Event):void
{
var loader:URLLoader=URLLoader(event.target);
var result:XML=new XML(loader.data);
var myXML:XMLDocument=new XMLDocument();
myXML.ignoreWhite=true;
myXML.parseXML(result.toXMLString());
var node:XMLNode=myXML.firstChild;
var n:int=int(node.firstChild.childNodes.length);
for(var i:int=0;i<n;i++)
{
Main.url_array.push(node.firstChild.childNodes[i].attributes['url']);
Main.descriptions_array.push(node.firstChild.childNodes[i].attributes['description']);
}
_fla.loadImages();
}
}
}
Then my xml just looks like:
PHP Code:
<root>
<images>
<img url="images/img_0.jpg" description="description 1"></img>
</images>
</root>
-
Just as an aside question, why are you extending XMLDocument and then using composition (creating an instance of it rather than using the inherited methods):
var myXML:XMLDocument=new XMLDocument();
As for the original question, to change the the x and y of the text, you would have to change the x and y coordinates if the text fiel that contains it, which I assume would be in the clip reference by _fla, so something like:
this._fla.texFieldName.x =
this._fla.texFieldName.y =
-
Im sorry I forgot I was using another .as file. Everything I need was in there.
And kortex I am not too familiar with var myXML:XMLDocument=new XMLDocument(); I will look in to it though. Thanks for your time
-
Well it a structural question. The class you posted extends XMLDocument which means it has all of the methods of that class, which makes this section of code a little strange:
var myXML:XMLDocument=new XMLDocument();
myXML.ignoreWhite=true;
myXML.parseXML(result.toXMLString());
You are essetially creating a XMLDocument in an XMLDocument class, which means there was no reason for this class to extend XMLDocument. I believe you should just be able to:
this.ignoreWhite=true;
this.parseXML(result.toXMLString());
since this class inherits all the methods in XMLDocument
-
oh you know i bet you are right, thanks i will try that out in just a min