Sunday, April 22, 2007

metadata.Frame

The closest thing we have to official documentation of the Frame metatag is at http://blogs.adobe.com/rgonzalez/2006/06/modular_applications_part_2.html. Important highlights include, "Note that the metadata is actually just an inline alias for the 'frames" compiler configuration option, which lets you explicitly specify the frame classes.' and "The rules [for the Frame tag] are a bit weird."

Examples from the mx framework are:
[Frame(factoryClass="mx.managers.SystemManager")] //mx.core.Application
[Frame(factoryClass="mx.core.FlexApplicationBootstrap")] // mx.core.SimpleApplication
[Frame(factoryClass="mx.core.FlexModuleFactory")] // mx.modules.Module and mx.modules.ModuleBase


Really you should read Roger's post if you want to know what's going on, but I'll give you the short version: The factory class defines the loader of the application /module which will load the application/module after the factory is initialized. So for Application, the factory class is defined as mx.managers.SystemManager. So when you start a flex application, SystemManager is instantiated which initializes many things and then starts the Application.

So this tells us about the factoryClass property, but we still have the extraClass property to discuss. You'll notice that the generated Class for your application (if you use the -keep-generated-actionscript option on your compiler) contains:

[Frame(extraClass="_{MyApp}_FlexInit")]

So here's what it is as best as I can figure out. This is also a inline shortcut for the compiler...almost. The -includes class option allows you to link classes to your project. Using this compiler option means you don't have to explicitly import the included class nor explicitly force code to link to the included class to use functions such as flash.utils.getDefinitionByName().

The extraClass tag does the same thing with one exception. The compiler option also causes default styles to be generated on compile (from framework.swc I think), while the inline tag does not generate these defaults. So if you want use the extraClass property of the Frame metatag, make sure you are not linking to a file which has default styles in the mx framework.

3 comments:

Brandon said...

Can someone post an example on how to use [Frame(extraClass="com.someUrl.SomeClass")]; to accomplish this statement:

"The -includes class option allows you to link classes to your project. Using this compiler option means you don't have to explicitly import the included class nor explicitly force code to link to the included class to use functions such as flash.utils.getDefinitionByName()."

That's exactly what I want to do - specify a flag inside of N number of widget classes to tell the Flex compiler 'hey - compile me even if I'm not instantiated or declared anywhere in any code or listed on any includes' - so that at runtime I can use either getDefinitionByName() or getClassAlias or something that allows me to instantiate com.someUrl.SomeClass at runtime.

argh said...

Brandon,

The [Frame] metadata doesn't have anything to do with that. You just need to add the -includes flag to your command line to do what you want.

Basically, 99% of the stuff in Flex is oriented around the Actionscript virtual machine. There are times however where it is convenient to be able to control the actual layout of the underlying Flash movie that contains the AS3 bytecode. The [Frame] metadata is one of the ways this is (semi-)visible to the outside world. It's mostly there for the compiler, but I tried to make it usable for the occasional funky feature. (It's also pretty cool for streaming modules in the same .swf. Alex Harui has written some stuff up on that.)

-rg

Sammy said...

Hi,

I have a custom SystemManager class properly instantiating my application to show a preloader within a 1-swf Flash game. All good.

Something I can't figure out is a way to have my document class (where the Frame tag exists), set a property that the SystemManager can read? Can I...

1) Send a variable through the Frame tag?
2) Read a variable from the SystemManager constuctor from the main constructor class? Dynamically (i.e. not hardcode the name of the main class)

"Flex", "ActionScript" and possibly "MXML" are probably trademarks of Adobe Systems Incorporated.
"Adobe" is a trademark of Adobe Systems Incorporated.
This site is in no way endorsed or sponsored by Adobe Systems Incorporated.
Content Copyright © 2007 Daniel Freiman.
Site Design Copyright by its copyright holder.
The Flex Non-Docs reserves the right to remove comments for any reason.
All ActionScript and MXML code (and ONLY ActionScript and MXML code) on this website is available under the MIT License.