Skip to main content
Daniel 0_o
Known Participant
October 17, 2009
Question

how do I load xml dynamically (flash/AS3)

  • October 17, 2009
  • 2 replies
  • 1423 views

Hi,

I'm trying to load xml file (UTF-8) to the TLF object. (dynamically, not with "send to stage")

I generated [markup...] few xml files with the TLF, and I like to load each one when user select a specific topic / button.

it seems very straight forward however im receiving an error access to undefined property

can any one plz reffer me to a sample how its done? (with flash CS4/AS3)

thx

Daniel

This topic has been closed for replies.

2 replies

Daniel 0_o
Known Participant
October 18, 2009

ok this is how its done with the flash component

to load the XML:

var loader:URLLoader = new URLLoader();

loader.load(new URLRequest("Content.xml"));

loader.addEventListener(Event.COMPLETE, loadCompleteHandler);

loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);

function loadCompleteHandler(e:Event):void

{

// myTextLayout is the name of the TextLayout component added to the .fla scene. 

// the name of the component using the Properties Panel.  e.target.data is the data read from the SimpleText.xml file

myTextLayout.xmlText = e.target.data;

}

my problem was with the property name ".xmlText"
Cheers,
Daniel

October 17, 2009

Could you maybe post some code to show how you're trying to do it now?

Adobe Employee
October 17, 2009

Here's some simple example code that might help:

package {
    import flash.display.Sprite;
   
    import flashx.textLayout.compose.StandardFlowComposer;
    import flashx.textLayout.container.ContainerController;
    import flashx.textLayout.elements.TextFlow;
    import flashx.textLayout.conversion.TextConverter;


    public class ImportMarkup extends Sprite
    {
        public function ImportMarkup()
        {
            var markup:String = "<TextFlow xmlns='http://ns.adobe.com/textLayout/2008'><p><span>Hello, World</span></p></TextFlow>";
            var textFlow:TextFlow = TextConverter.importToFlow(markup, TextConverter.TEXT_LAYOUT_FORMAT);
            textFlow.flowComposer.addController(new ContainerController(this, 200, 50));
            textFlow.flowComposer.updateAllControllers();
        }
    }
}

Adobe Employee
October 17, 2009

One follow on -- it looks like from your post you are using the original version we posted on Labs with the plug-in for Flash Authoring. That's almost a year old now.We have more recent postings that come out with the Flex Open Source. You could pick up one of these (for example, from the Flex public beta 2) and use the TLF SWC that comes with it (textLayout.SWC), and link against that SWC from your Flash project. We've made a lot of changes since the original release, and you'd get all the benefit of those. We've changed the API in a few places, and the example code I posted will only work with the newer version. The only thing you won't be able to do is use the panel UI plug-in.

Hope this helps,

- robin