0

I need to build an XML file that is read by this code.
I can't figure out how to do it.

public function formDoneLoading(param1:ServerConfig) : void
{
    this.serverConfig = param1;
    this.loadAvatars("boy");
    this.loadAvatars("girl");
    this.hairXMLLoader = new URLLoader(new 
    URLRequest(this.avatarPath + "defaultHair.xml"));
    this.hairXMLLoader.addEventListener(Event.COMPLETE,this.hairXMLLoaded);
    //this.hairXMLLoader.load(); //# this part is missing in original code
    
}

private function hairXMLLoaded(param1:Event) : void
{
    var _loc2_:XML = XML(this.hairXMLLoader.data);
    this.BOY_INIT_HAIR = _loc2_.defaultHair.@boy;
    this.GIRL_INIT_HAIR = _loc2_.defaultHair.@girl;
}

Is what I'm doing right? This is how you write the XML document

My example XML:

20
  • 1
    You never start the actual loading. That's probably why it doesn't work as you expect it to. Also, XML(...) is type casting, you might want trying new XML(...) instead. Commented Sep 4, 2022 at 10:14
  • Please post the code or error into your question, not an image. Commented Sep 4, 2022 at 10:19
  • Hi guys, I don't get an error, it just doesn't load the information that is inside the xml file Commented Sep 4, 2022 at 12:06
  • 1
    @JustMoon As I pointed out, you just don't load it. Commented Sep 4, 2022 at 13:24
  • Hi, Why not? If I don't load it, I'm missing parts in my flash game, and if I don't have it, I see a in developer toolbox error because the file doesn't exist Commented Sep 5, 2022 at 5:07

1 Answer 1

1
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;

XML.ignoreComments = false;
XML.ignoreWhitespace = true;

public const FNAME:File = new File(File.applicationDirectory.nativePath + "/myfile.xml");
public const FSTREAM:FileStream = new FileStream();
FSTREAM.open(FNAME, FileMode.READ);
var myxml:XML = new XML(<myxmlroot/>);
myxml = new XML(FSTREAM.readUTFBytes(FSTREAM.bytesAvailable));
FSTREAM.close();
Sign up to request clarification or add additional context in comments.

2 Comments

Nice, but it won't work in browser.
@Organis you are right; this is a snippet for AIR SDK only

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.