Hi Tyler,

Since your swfloaders are applications you can listen for the
applicationComplete event via the swfloader.content property. This event
fires when all children have issued creationComplete events (including your
viewstack). You don't have to worry about using a timer.

Set up your listeners on the swfloader as you are currently doing but add
one for the INIT event. In the event handler you can add another listener on
swfloader.content (your sub application).  For example.

       private function handleInit(event:Event):void
       {
           _swfloader.content.addEventListener(
FlexEvent.APPLICATION_COMPLETE, handleApplicationLoaded);
       }

       private function handleApplicationLoaded(event:Event):void
       {
           _applicationLoaded = true;
           dispatchEvent(new SWFAppEvent( SWFAppEvent.READY ));
       }

In the above code I am waiting for my custom event READY to fire before I
start referencing it in the parent.

This is something I did before modules was included in the framework so
there might be some duplication ?? Have you looked at modules?

Hope that helps.

Cheers
Angus



On 02/03/07, tyriker <[EMAIL PROTECTED]> wrote:

  Okay, that makes sense. Sort of...

I already have an event listener setup for the SWFLoader objects. I try to
check if the loaded app is finished initializing and proceed, otherwise I
try again in a second. Here's a snippet:

--------------
<mx:SWFLoader source="source_to_app.swf" complete="loaderComplete(event);"
trustContent="true"/>

<mx:Script>
  <![CDATA[
    private function loaderComplete(e:Event):void
    {
      if (e.currentTarget.content.application) //is the app initialized?
      {
         //trigger the generation of the chart...
      }
      else //if not, try again in 1 second
      {
        setTimeout(loaderComplete, 1000, e);
      }
    }
  ]]>
</mx:Script>
--------------

Is this the right way to do such a thing? It seems to work for me. Before
implementing this, I was attempting to access
e.currentTarget.content.application["varname"] before the variables
existed, and that for sure caused runtime errors.

One thing along these lines that may be the problem...the loaded app
switches "states" before working on building the chart. The new state adds
the chart object to the display. So does the chart object not exist before
we switch states? Is it possible I'm attempting to access objects in the new
state before the state is fully built?

When the code:

currentState = 'chart';

is executed, is the state fully built before the next line of code is
executed? Or could something like this cause a problem:

currentState = 'chart';
itemInChartState.visible = false //as an example

Is it possible itemInChartState doesn't exist yet?

Thanks for the help.
Tyler


--- In flexcoders@yahoogroups.com, "Angus Johnson" <[EMAIL PROTECTED]> wrote:
>
> That error indicates that your are referencing something that doesn't
exist
> yet.
>
> You need to set listeners of the swfloader(s) to ensure that they are
loaded
> and complete. See the doc's which has an example of setting them.
>
> Wait for the complete event then fire your charting.
>
> Post back if you need more help.
>
> Angus

Reply via email to