A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: [AS3] Load dynamic XML

  1. #1
    Senior Member whytefly's Avatar
    Join Date
    Jun 2004
    Location
    submerged
    Posts
    363

    [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']);


  2. #2
    Senior Member
    Join Date
    Jun 2002
    Location
    Ljubljana, Slovenija
    Posts
    168
    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.

  3. #3
    Senior Member whytefly's Avatar
    Join Date
    Jun 2004
    Location
    submerged
    Posts
    363

    Wink

    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

  4. #4
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    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 =
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  5. #5
    Senior Member whytefly's Avatar
    Join Date
    Jun 2004
    Location
    submerged
    Posts
    363
    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

  6. #6
    OOP is one letter from OOPS kortex's Avatar
    Join Date
    Aug 2005
    Location
    New Hope, PA
    Posts
    2,668
    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
    Jeremy Wischusen
    Flash - Flex - LAMP - Web Developer Purple Inc
    AS OOP FAQ-Best Practices Thread | Flashkit OOP Tutorials | Purple Inc (day job) | Blog


  7. #7
    Senior Member whytefly's Avatar
    Join Date
    Jun 2004
    Location
    submerged
    Posts
    363
    oh you know i bet you are right, thanks i will try that out in just a min

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center