Thanks all for your replies. Slight delay in responding due to trying to solve the problem whilst trying to make tangible progress on the project at the same time! Muzak, although I didn't try your suggestion, I suspect it would have worked but I feel it's much the same as the solution I used in the sense that it's tricking the compiler. If I'm tricking the compiler it means I probably haven't understood something properly and that keeps me awake at night :)
Steven, thanks for that link. It's very interesting but, in this case, my initial instinct and August's suggestion was correct - I just needed to compile the class into my View and then cast gameLoader.content when I want to access its custom methods/properties. August - you were exactly right! I had tried this before but, what I discovered was that the game I was loading (authored by someone else) was throwing a runtime error when I tried to run it and I had misinterpreted the error as a problem with my code. Weirdly, this runtime error was not thrown when I ran the game on its own! Anyway, I tracked down and fixed the problem in the game code and now all is working well. August, if you want to discuss our frameworks and MVC further, feel free to contact me direct at [EMAIL PROTECTED] Thanks all, Adrian Park On Jan 9, 2008 1:38 AM, Muzak <[EMAIL PROTECTED]> wrote: > Have you tried casting to MovieClip? > > regards, > Muzak > > ----- Original Message ----- > From: "Adrian Park" <[EMAIL PROTECTED]> > To: <Flashcoders@chattyfig.figleaf.com> > Sent: Tuesday, January 08, 2008 8:45 PM > Subject: [Flashcoders] How to call custom method on loaded AS3 swf? > > > > This is my first post to the list in 2008 so hi and compliments of the > > season to y'all. > > So, here's the context... > > > > I have an application framework built in AS3 and based on the MVC > pattern. > > One of my Views loads a compiled swf also built in AS3. When it is that > > View's turn to be displayed, it gets added to the display list and then > > needs to call a custom method on the loaded swf so that loaded swf does > its > > thing (it's a game). > > > > Here's the problem... > > > > Although I can invoke the required method on the loaded swf, I couldn't > get > > the compiler to stop complaining (it's compiling in Strict mode) so I > had to > > do a bit of a kludge to trick the compiler. I am sure there is a better > and > > proper way of doing this - can you tell me what it is? > > > > Here's the code that loads the game swf (for the sake of context)... > > > > gameLoader = new Loader(); > > // some listeners registered here > > var request:URLRequest = new URLRequest( gameURL ); > > gameLoader.load(request); > > > > The Document Class of the swf at 'gameURL' contains a method call > 'startup' > > and this is the one I want to invoke. So I tried this... > > gameLoader.content.startup(); > > > > Predictably, the compiler utters the following... > > "1061: Call to a possibly undefined method startup through a reference > with > > static type flash.display:DisplayObject." > > > > I tried a few things (including casting gameLoader.content to the > Document > > Class) but the only thing I could get to work is this... > > gameLoader.content["startup"](); > > > > Any ideas? Thanks in advance. > > > > Adrian Park > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders