I finally found a neat way to decorate SWF7 classes with SWF8 functionality. It
worked with a simple test case so I still need to test it against a more
complex example but the basic idea is the following:
- there's an interface called IFoo that defines all functions that should be
available later in the game (i.e. browse())
- there's a class called FooStub that implements the interface IFoo but does
not provide any functionality
- there's a class called FooImpl that also implements the interface IFoo and
defines the full functionality (e.g. use some FP8 features like FileReference
and call browse on it)
The magic comes with a fla file called decorator.fla - the decorator.fla
contains nothing but a single function in the frame script of frame 1 called
decorateStub:
function decorateStub(fooStub:Function):Void {
fooStub.prototype = FooImpl.prototype;
}
this compiles to decorator.swf and gets loaded into the Flex 1.5 application by
using mx.controls.Loader.
Inside the Flex application after the Loader completes loading the
decorator.swf the FP8 functionality gets added to the FooStub class by doing
private function decoratorLoaded(event:Object):Void {
// event.target is the Loader
event.target.content.decorateStub(FooStub);
}
Now the FooStub class points to the FooImpl class and doing a new FooStub()
really runs the FooImpl code - by using the IFoo interface everything plays
nicely with the Flex compiler.
Again, I have to test a few things but this really seems to work nicely.
Dirk.________________________________ Von: [email protected] im Auftrag von Roger Gonzalez Gesendet: Mi 02.11.2005 21:16 An: [email protected] Betreff: RE: [flexcoders] Loading a Flash 8 compiled AS 2.0 class into a Flex app and instantiate it Classes are actually just magic definitions on _global. If you were to look at the decompiled code that sets up a new class, you'd see something like: if (!_global.SomeClass) { _global.SomeClass = ... } So, it goes out of its way to not redefine classes. First one in wins. (Sidebar: Flex 2 and Flash 8.5 provide a more sophisticated mechanism using ApplicationDomain to let you better partition or share class defs, however you like.) Now, it also turns out that you're kind of in trouble here - cross-SWF definitions get really weird in FP7 and below. AS code and assets follow different rules. The assets in the child are really only visible when instantiated from a code context springing from the child itself. Its maddening! (Hence part of the reason for making it sane in Flash 8.5!) SWFs loaded as RSLs are a special case in FP8 and below. Maybe you can exploit that... compile against a Flex stub, then sub in the Flash version at runtime? Remember not to touch any Flex classes from inside Flash, you need to basically partition things. You can try digging up the Flex4Flash.zip file and pulling out the Flex components for compiling in Flash, but there are a lot of scary gotchas with that. Anyway, this is a really cool direction to check out, let us know if you have any luck! -Roger Roger Gonzalez mailto:[EMAIL PROTECTED] > -----Original Message----- > From: [email protected] > [mailto:[EMAIL PROTECTED] On Behalf Of Dirk Eismann > Sent: Wednesday, November 02, 2005 8:39 AM > To: [email protected] > Subject: [flexcoders] Loading a Flash 8 compiled AS 2.0 class > into a Flex app and instantiate it > > Hi, > > I'm having a hard time figuring out what happens here. I want to load > Flash 8 bytecode into my Flex 1.5 application to gain access to FP8 > features (the app runs on FP8, SWF8 gets loaded into Flex app by using > mx.controls.Loader) but this only works to a certain degree. > > Instead of putting all functionality directly into the timeline of the > SWF8 file and call those functions from Flex by doing > loader.content.someFunction(), the SWF should really only act as a > "library" for AS 2.0 classes. I only want to place something like > > foo.bar.MyClass; > > into the first frame of the SWF8 source file to get the class compiled > in - this should be sufficient, right? > > Now, in my Flex 1.5 application I load the external SWF8 file > and after > it got loaded I want to create a new instance of foo.bar.MyClass (the > SWF8 version of course) > > So in my Flex 1.5 code I have something like this > > private function swfLoaded():Void { > var foo:foo.bar.MyClass = new foo.bar.MyClass(); > } > > this of course compiles foo.bar.MyClass into the Flex 1.5 SWF > file - but > I thought that loading in the SWF8 file would somehow "overwrite" the > bytecode with the "new" version... > > Now the big question is: during runtime, which version of the > class will > be instantiated? The class that got compiled into the SWF7 file or the > newly loaded version of the SWF8 file? > > Any thoughts? > > Roger, you there? > > Thanks, > Dirk. > > > ------------------------ Yahoo! Groups Sponsor > --------------------~--> > Fair play? Video games influencing politics. Click and talk back! > http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/nhFolB/TM > -------------------------------------------------------------- > ------~-> > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Search Archives: > http://www.mail-archive.com/flexcoders%40yahoogroups.com > Yahoo! Groups Links > > > > > > > -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links ------------------------ Yahoo! Groups Sponsor --------------------~--> Most low income households are not online. Help bridge the digital divide today! http://us.click.yahoo.com/cd_AJB/QnQLAA/TtwFAA/nhFolB/TM --------------------------------------------------------------------~-> -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com Yahoo! Groups Links <*> To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ <*> To unsubscribe from this group, send an email to: [EMAIL PROTECTED] <*> Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
<<winmail.dat>>

