A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: button for loading XML data

  1. #1
    Member
    Join Date
    Nov 2005
    Posts
    31

    button for loading XML data

    Hi

    I want to start by saying that my AS-skills are pretty limited, because I am new to the subject, so please bear with me


    After having seen through this tutorial

    http://www.kirupa.com/developer/flas...ml_as3_pg6.htm I got help from a nice person to get a code, that would load my XML data into my SWF, after pressing a button. He even made an explanation for me through the code:

    Code:
    // this objects loads the xml file
    var xmlLoader:URLLoader = new URLLoader();
    
    // this will be your xml data once loaded, now its empty
    var xmlData:XML;
     
    // my_button is the instance name of the button on the stage
    my_button.addEventListener( MouseEvent.CLICK, onClickFunction );
    
    // hey, someone pressed the button, lets do something
    function onClickFunction( a_event:MouseEvent ):void
    {
        // we want to know when its loaded, so we can do stuff with it
        xmlLoader.addEventListener(Event.COMPLETE, onXMLLoaded);
       
        // we want to load the xml
        xmlLoader.load(new URLRequest("tracks.xml"));    
    }
    
    // the xml is loaded so lets do what this function says
    function onXMLLoaded( a_event:Event ):void
    {    
        // you remember? the xml data object created before? now it gets content
        xmlData = new XML( xmlLoader.data );
        trace("horray, the xml is here" );
        trace(  xmlData );
    }
    And and Content of my XML data is following so far:

    http://pastebin.com/wf9C0EY2

    I would like to make a button in Flash that reads the XML file, and when pressed, it shows the track Title, corresponding to the Genre or the Mood, specified in the XML file.

    For instance: The buttons name is Aggressive and when I press it, all the tracks that have "Aggressive" as the Mood (in the XML file), will be called forth.

    How do I do that?


    Here are the files for the project: http://www.toonhaze.com/project.rar
    ..
    ..
    ..

  2. #2
    WohOoooooo zompo's Avatar
    Join Date
    Oct 2008
    Location
    Sweden
    Posts
    138
    Here is a good page to get you started:

    http://www.republicofcode.com/tutorials/flash/as3xml/


    Try out my game http://alpha.bombwar.com - Alphakey: fkaplha

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