A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: External variables/XML, flash 9 export

  1. #1
    Member
    Join Date
    Nov 2007
    Location
    Brazil
    Posts
    47

    External variables/XML, flash 9 export

    How to load external variables or a XML file in 3DFA using AS3/flash 9?
    []'s
    leocavalcante.com

  2. #2
    Member
    Join Date
    Nov 2007
    Location
    Brazil
    Posts
    47
    finally
    here is it for who wanna know!

    file meuxml.xml
    Code:
    <?xml version="1.0" encoding="utf-8" ?>
    
    <itens>
    
    <item1>Item 01</item1>
    <item2>Item 02</item2>
    
    </itens>
    AS:
    Code:
    var output = element ("Edit 18");
    var xml:XML;
    var loadXML = new URLLoader();
    
    loadXML.load(new URLRequest("meuxml.xml"));
    loadXML.addEventListener(Event.COMPLETE, xmlOk);
    
    function xmlOk(event:Event) {
    xml = XML(event.target.data);
    output.text = xml;
    }
    now I'm trying to load variables, any success I reply!
    []'s
    leocavalcante.com

  3. #3
    3DFA hobby scripter LewxX²'s Avatar
    Join Date
    Jul 2006
    Location
    Germany, Karlsruhe
    Posts
    198
    I'm at the same point.

    But I don't know how to handle with the loaded xml.

    I need to get my game to read the xml map data
    Mapeditor
    Game itself (Alpha v0.0)

    an someone help me?

    simplified XML Example:
    Code:
    <mapdata>
    <level>
    <name>map one</name>
    <mapnr>44</mapnr>
    <geglvl>1</geglvl>
    </level>
    <level>
    <name>map two</name>
    <mapnr>45</mapnr>
    <geglvl>3</geglvl>
    </level>
    </mapdata>
    How can I extract the xml to get a result like:

    map_nr = loaded_xml.level[0].mapnr // = 44
    enemy_lv = loaded_xml.level[0].geglvl // = 1
    map_name = loaded_xml.level[0].name // = "map one"

    map_nr = loaded_xml.level[1].mapnr // = 45
    enemy_lv = loaded_xml.level[1].geglvl // = 3
    map_name = loaded_xml.level[1].name // = "map two"

    or even better:
    map_name = loaded_xml.mapnr[44].name // = "map one"
    map_name = loaded_xml.mapnr[45].name // = "map two"

    that would be awesome
    Last edited by LewxX²; 02-15-2009 at 03:40 PM.
    sorry for my bad school English
    btw. visit my Page: projects.lewxx.de
    or lewxx.de (<= German)

  4. #4
    3DFA hobby scripter LewxX²'s Avatar
    Join Date
    Jul 2006
    Location
    Germany, Karlsruhe
    Posts
    198
    Ok,

    I figured something out:

    my_xml.firstChild.childNodes[0].childNodes[0].firstChild.nodeValue = map one
    my_xml.firstChild.childNodes[1].childNodes[0].firstChild.nodeValue = map two

    my_xml.firstChild.childNodes[0].childNodes[1].firstChild.nodeValue = 44
    my_xml.firstChild.childNodes[1].childNodes[1].firstChild.nodeValue = 45

    that is a big step!

    but i like to have it like:
    my_xml.firstChild.childNodes[1].name.nodeValue = map one
    and
    my_xml.firstChild.childNodes[1].mapnr.nodeValue = 44

    but that doesnt work

    What am I doing wrong?

    http://flash.lifestylepics.de/xenic2/xml_test.rar << movie
    Last edited by LewxX²; 02-15-2009 at 05:24 PM.
    sorry for my bad school English
    btw. visit my Page: projects.lewxx.de
    or lewxx.de (<= German)

  5. #5
    Member
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    76
    Maybe this is helpful:

    Code:
    var output:String = "Watch this:\n";
    
    /*
    +------------------------+
    | ONLY FOR AS3 / FLASH 9 |
    +------------------------+
    */
    
    // xml definition
    
    var xml:XML =
    <mapdata>
    	<level>		// xml.child(0)
    		<name>map one</name>	// xml.child(0).child("name")
    		<mapnr>44</mapnr>	// xml.child(0).child("mapnr")
    		<geglvl>1</geglvl>	// xml.child(0).child("geglvl")
    	</level>
    
    	<level>		// xml.child(1)
    		<name>map two</name>	// xml.child(1).child("name")
    		<mapnr>45</mapnr>	// xml.child(1).child("name")
    		<geglvl>3</geglvl>	// xml.child(1).child("name")
    	</level>
    </mapdata>;
    
    
    // xml.child("level") returns a XMLList object that contains
    // all children with the name "level".
    
    var list:XMLList = xml.child("level");
    
    
    // so you can simply use a 'for each' loop to loop through
    // each node.
    // 3DFA throws an exception at this point but it will
    // work on export.
    
    for each (level in list)
    {
    	output += level.child("name")+"\n";
    	output += level.child("mapnr")+"\n";
    	output += level.child("geglvl")+"\n";
    }
    
    // you can also use the classic 'for' loop.
    
    // length() returns the length of a XMLList.
    
    /*var number:Number = list.length();
    
    for (var i:Number=0; i<number; i++)
    {
    	output += list[i].child("name")+"\n";
    	output += list[i].child("mapnr")+"\n";
    	output += list[i].child("geglvl")+"\n";
    }*/

    That's the way I would do it.
    Notice that it will only work with Flash 9.

    Your code looks like you are using Flash 8. I suspect that can't help you then, because since I learned how to code with ActionScript 3 and Java (which is virtually the same), ActionScript 2 is just too inefficent and complicated for me.

    I really advise you to use Flash 9 because you simply get much more performance in comparison with Flash 8. But I also know that it's hard work to learn thinking in classes and packages as you have to in AS3.

    You just need this 'click'-moment to realize how easy classes are :-)

    However...

    Cheers,
    Leifi

  6. #6
    3DFA hobby scripter LewxX²'s Avatar
    Join Date
    Jul 2006
    Location
    Germany, Karlsruhe
    Posts
    198
    wow, vielen dank leifi ^^



    Edit:
    But I think 3DFA don't work that good with Flash 9 :-\

    When I export as Flash 9 all my text-boxes an even vector fonts are corrupt.

    Also my code that should work with flash 9 does whatever he wants.
    Last edited by LewxX²; 02-16-2009 at 06:07 AM.
    sorry for my bad school English
    btw. visit my Page: projects.lewxx.de
    or lewxx.de (<= German)

  7. #7
    Member
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    76
    bitteschön

    Yes, you need some workarounds to get AS3 code to work but once you got it, it's really fine

    The textboxes are really bad, I often create them by myself to get what I want... And the vector fonts always have some kind of shadow behind them.. that's annoying...

    However, you can find a workaround for nearly every problem

  8. #8
    3DFA hobby scripter LewxX²'s Avatar
    Join Date
    Jul 2006
    Location
    Germany, Karlsruhe
    Posts
    198
    k, I'll try
    sorry for my bad school English
    btw. visit my Page: projects.lewxx.de
    or lewxx.de (<= German)

  9. #9
    Leo, if you find this out of place i will start a new thread!?

    Otherwise, i am looking for help with xml myself.

    I know nothing about the language and after looking at the tutorial and this thread i still can't get my head around the basics.

    I would like to try to get the video player (panda) that is in the samples to load any external video file that is within a list.

    Maybe videos from 1 to 10 and on a simple link click it will open any one of the ten videos. It could be a next and last button or even better a list of the videos with name and time displayed. A video jukebox if you like that can have videos uploaded to be played online.

    Anyone got any advice or can even help me with this would be highly appreciated, all credit would be announced on my site.

    thanks in advance

  10. #10
    Junior Member
    Join Date
    Jan 2005
    Posts
    1
    I am trying to do the same thing , ive tried so many scripts but cant figure out how to call the cript from the buttons, play stop etc...

    I got this far from tuorials at as3 forums but even if the code in the script is right , I dont know how it will populate anything. How do i asscoitae it to a text or edit box ? Do you use the call script under button mousedown to call element by script and select function playsong ?

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

    var my_songs:XMLList;
    var my_total:Number;

    var my_sound:Sound;
    var my_channel:SoundChannel;

    var url = "playlist.xml";
    var my_xml = <xml><dummy>data</dummy></xml>

    var loader = new URLLoader;
    loader.addEventListener ("complete", completeHandler);
    loader.load (new URLRequest (url));

    function completeHandler (event:Event)
    my_xml = new XML (loader.data);
    my_songs = myXML.SONG;
    my_total = my_songs.length();

    function playSong(mySong:Number):void{
    var myTitle = my_songs[mySong].@TITLE;
    var myArtist = my_songs[mySong].@ARTIST;
    var myURL = my_songs[mySong].@URL;

    title_txt.text = myTitle;
    artist_txt.text = myArtist;

    if (my_channel){
    my_channel.stop();
    }

    my_sound = new Sound();
    my_sound.load(new URLRequest(myURL));
    my_channel = my_sound.play();
    }

    my_sound = new Sound();
    my_sound.load(new URLRequest(myURL));
    my_channel = my_sound.play();

    next_btn.addEventListener(MouseEvent.CLICK, onNext);
    function onNext(e:MouseEvent):void{
    current_song++;
    if (current_song>=my_total){
    current_song=0;
    playSong(current_song);
    }
    }

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