Skip to main content
Participant
August 12, 2010
Question

XML Content and Linked containers

  • August 12, 2010
  • 1 reply
  • 654 views

Hi, I just downloaded the trial of CS5 and I was wondering how to do the following.

I have 5 XML files that load into my site.  Each one is called by a button click.  On the initial stage I have 2 containers which are linked for overflow text.  So here is my problem.  When I click on any button the content in the second text box stays there and only the content of the first one changes.

SO question...

How do i get the new text that is loaded from the XML to flow to the second container? OR the second container clear its content if there is no overflow?

Thanks so much!!

Kathy

This topic has been closed for replies.

1 reply

Inspiring
August 13, 2010

Without seeing any code its hard say.  Are you calling textFlow.flowComposer.updateAllControllers() after the the new text is imported?  How are you linking these containers, programmatically or thru the Flash IDE?

At any rate, I came across these 2 articles that may help:

http://help.adobe.com/en_US/flash/cs/using/WSb03e830bd6f770ee-4b0db644124bbdb363d-8000.html#WSb03e830bd6f770ee2571a7bc124bce0329e-8000

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flashx/textLayout/container/ContainerController.html?allClasses=1#includeExamplesSummary

ksamounAuthor
Participant
August 13, 2010

HI and thanks so much for responding! So I added everything I THINK I need to add and its still not updating them. This is my first time trying this so I'm not sure if my code is correct but here is the code. The two containers I have on the stage are m_txt and o_txt. Thanks so much for your help!

import flash.events.MouseEvent;

import flash.net.URLLoader;

import flash.net.URLRequest;

import flashx.textLayout.compose.StandardFlowComposer;

import flashx.textLayout.container.ContainerController;

import flashx.textLayout.conversion.TextConverter;

import flashx.textLayout.elements.TextFlow;

import flash.external.ExternalInterface;

import flash.display.StageScaleMode;

stage.scaleMode = StageScaleMode.NO_SCALE;

stage.align = StageAlign.TOP_LEFT;

//Preloader code start

var i : uint = this.numChildren;

for (; i > 0; i--) this.getChildAt(i - 1).alpha = 0.0;

var tf : TextField = new TextField;

tf.text = "Now loading...";

tf.width = 1000;

addChild (tf);

// Preloader initialization done. If you don't like it, decomment the next line

//removeChild (tf);

var uarray : Array = ["home.xml","about.xml","philosophy.xml","contact.xml"];

var harray : Array = [];

var marray : Array = [];

var qarray : Array = [];

var barray : Array = [];

i = uarray.length - 1;

var uloader : URLLoader = new URLLoader;

uloader.addEventListener ("complete", completeLoaderChain);

uloader.load (new URLRequest(uarray));

function completeLoaderChain (e:*) : void

{

var d : XML = XML(e.target.data);

harray = d.head;

marray = d.main;

qarray = d.quote;

if (i-- == 0) enableButtons();

else uloader.load (new URLRequest(uarray));

}

function enableButtons () : void

{

i = this.numChildren;

for (; i > 0; i--) this.getChildAt(i - 1).alpha = 1.0;

if (this.contains (tf)) removeChild (tf);

barray[0] = home_btn;

home_btn.addEventListener ("click", buttonClicked);

barray[1] = about_btn;

about_btn.addEventListener ("click", buttonClicked);

barray[2] = philosophy_btn;

philosophy_btn.addEventListener ("click", buttonClicked);

barray[3] = contact_btn;

contact_btn.addEventListener ("click", buttonClicked);

}

function buttonClicked (e:*) : void

{

var textFlow:TextFlow;

var m_txt:ContainerController = new ContainerController(m_txt)

var o_txt:ContainerController = new ContainerController(o_txt);

// import the text flow from XML using TextConverter and assign a StandardFlowComposer

textFlow = TextConverter.importToFlow(uarray[id], TextConverter.TEXT_LAYOUT_FORMAT);

textFlow.flowComposer = new StandardFlowComposer();

var id : int = -1;

for (var l = 0; l < barray.length; l++) {

if (barray == e.target) {

id = l;

l = barray.length;

}

}

textFlow.flowComposer.addController(m_txt);

textFlow.flowComposer.addController(o_txt);

h_txt.text = harray[id];

m_txt = marray[id];

q_txt.text = qarray[id];

textFlow.flowComposer.updateAllControllers();

//The following two lines will call a JavaScript function "resizeh"

/*var resizeto:Number = m_txt.height + m_txt.y ;

if( resizeto < 550){

resizeto = 550;

ExternalInterface.call("resizeh", resizeto);

} else {

ExternalInterface.call("resizeh", resizeto);

}*/

}

Inspiring
August 13, 2010

At first glance, this isn't good:

var m_txt:ContainerController = new ContainerController(m_txt);

var o_txt:ContainerController = new ContainerController(o_txt);

Name collision.  Change it to something like this:

var m_Controller:ContainerController = new ContainerController(m_txt);

var o_Controller:ContainerController = new ContainerController(o_txt);

...then update these lines:

textFlow.flowComposer.addController(m_Controller);

textFlow.flowComposer.addController(o_Controller);

Also, I am not sure what this is doing:

m_txt = marray[id];

m_txt should be a Sprite or subclass of it since you pass it to the ContainerController construct.  I dont think its good to give it value directy since the textFlow instance is using it. 

And here:

textFlow = TextConverter.importToFlow(uarray[id], TextConverter.TEXT_LAYOUT_FORMAT);

That returns the filename, right?  I think you would want to pass variable d from your  completeLoaderChain().

Welcome to TLF!