I replied earlier, but my post has never shown up. Anyway...

I didn't know anything about modules, but did some reading about them.
Seems ideal for what I'm going to be doing, but I'll tackle that later.

So I implemented the listeners like you described, and it worked great.
I'm now able to manipulate items within the loaded app, without using
the timer method I described earlier. Thanks for that!

But my original problem still exists. I still get a runtime error about
95% of the time. The error starts with:

TypeError: Error #1034: Type Coercion failed: cannot convert
mx.core::[EMAIL PROTECTED] to mx.core.IFactory.
     at mx.charts.series::BarSeries/get
legendData()[C:\dev\flex_201_gmc\sdk\frameworks\mx\charts\series\BarSeri\
es.as:178]
...etc...

So I commented out all of the BarSeries lines of code from my app (about
5 lines), and then received a different but very similar error at
runtime (cannot convert ...Stroke to IStroke). Using trace() I've
followed through to progression of my code, compared to when the runtime
error occurs.

The first thing I do is change the currentState to the new state, which
contains the chart. Then I set all the properties of the chart, then my
code is done. It is after that when the runtime error occurs. Looking at
the app itself, the new state hasn't been 'painted' on the screen yet,
so it seems the error occurs when the Flash Player attempts to display
the new state. So it feels like the error is caused by code I don't have
control over (Adobe's code). I've also tried using 'enterState' event
listeners, but it resulted in the same runtime error.

Yeah, kind of frustrated. The only thing I can think of is scrapping
states, and just using ActionScript to change the display. Maybe that's
the only way to make it reliably work.




--- In flexcoders@yahoogroups.com, "Angus Johnson" <[EMAIL PROTECTED]>
wrote:
>
> 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" gusjohnson@
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