inside package - apache-flex

Similar to the [Embed ()] tag I know from flex ¿ what's for the following code:
[Event(name="init",type="flash.events.Event")]
[Event(name="ioError",type="flash.events.IOErrorEvent")]
[Event(name="securityError",type="flash.events.SecurityErrorEvent")]
I've found this in several libraries I used, the one show here is from Flartoolkit, the code is defined inside the package, after the imports.
By the way, is this code executed when I compile in flash IDE?
Thanks,
.am

That's actionscript's metadata tags. These specific ones declare that the class below them throws these kind of events of these types.
http://livedocs.adobe.com/flex/3/html/metadata_3.html#159710
This metadata gets bound to the class at runtime and is available for access

[Event] metadata is for the Flex framework and are not used by the Flash IDE, but you can use of the [Embed] metadata under Flash CS4

Related

The meaning of "External" linking mode in Flex Builder

There are three modes to link an SWC library to a flex application: "Merged into code", "External" and "RSL". I understand what is "RSL", but I don't understand what is "External".
"RSL" works just fine for me, without any code changes. However, External doesn't work for me. Although my application starts, the classes in the SWC set to External are never found.
What is the meaning of "External" if it is not "RSL" ? How do I make use of that ?
Thank you,
Boris
Defining a class as External allows the Flex compiler to link to a particular class at compile time but does not cause it to be included in the generated SWF.
The general use for External classes is where you have multiple modules that use a shared library. It would be redundant to include the shared class definitions in every single module and the External keyword allows you to control how these classes are compiled into your libraries.
More information is available at the following locations:
http://web.archive.org/web/20101007120528/http://www.wannaknowflex.com/2010/05/flex-linkage-difference-between-rsl-and-external/
http://www.flexafterdark.com/docs/Flex-Libraries
(external-library-path and load-externs compiler information):
http://www.newtriks.com/?p=802

Can't find compiled resource bundles

I am using Adobe Flash Builder 4.
I've run into this issue with my latest project, but I was able to re-create it with an almost empty project.
Here is what I've done.
Created a new Flex Project
Created a locale/en_US folder within this project.
Added a class that extends SparkDownloadProgressBar. All this class does is attempt to create a Label.
When I try to debug this application, I get the following error.
Error: Could not find compiled resource bundle 'components' for locale 'en_US'.
at mx.resources::ResourceManagerImpl/installCompiledResourceBundle()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\resources\ResourceManagerImpl.as:340]
at mx.resources::ResourceManagerImpl/installCompiledResourceBundles()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\resources\ResourceManagerImpl.as:269]
at mx.resources::ResourceManagerImpl/processInfo()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\resources\ResourceManagerImpl.as:387]
at mx.resources::ResourceManagerImpl()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\resources\ResourceManagerImpl.as:122]
at mx.resources::ResourceManager$/getInstance()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\resources\ResourceManager.as:111]
at mx.core::UIComponent()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\core\UIComponent.as:3728]
at spark.components.supportClasses::TextBase()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\supportClasses\TextBase.as:154]
at spark.components::Label()[E:\dev\4.0.0\frameworks\projects\spark\src\spark\components\Label.as:384]
at Preloader()[C:\SVN\Games\Social\Test\src\Preloader.as:21]
at mx.preloaders::Preloader/initialize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\preloaders\Preloader.as:253]
at mx.managers::SystemManager/http://www.adobe.com/2006/flex/mx/internal::initialize()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:1925]
at mx.managers::SystemManager/initHandler()[E:\dev\4.0.0\frameworks\projects\framework\src\mx\managers\SystemManager.as:2419]
The Flex Compiler/Additional Compiler Arguments section does contain "-locale en_US", but I do not want to just remove this as I am planning to have this load different property files based on the localization region at run-time and how I understand it, I will need to add each locale that I am planning to use on the compile argument line.
I am at a loss as to how to attack this problem. If you need anymore information from me to help with this, I will be more than happy to provide it. Thanks ahead of time for the help!
This might be caused by the fact, that Preloader loads the actual framework, so you can't use the Flex's classes until it loads. Use standard TextField for it and it should work fine.

ModuleBase vs. Module

Does anyone have insight into when to use mx.modules.ModuleBase over mx.modules.Module? The documentation that I have seen isn't very clear on what each was designed for. What do they mean by "interacts with the framework" exactly? Does it just come down to visual vs. non visual components? Obviously a BaseModule which doesn't interact with "the framework" isn't going to be very useful so any realistic subclass of BaseModule would probably interact with the framework in some capacity. My guess is that Adobe provided ModuleBase so that developers could extend from the minimal amount of code necessary to just get something loaded into the vm at runtime. Any ideas? Thanks
Flex Developer's Guide pg.990
Extending the Module class is the same
as using the tag in an
MXML file. You should extend this
class if your module interacts with
the framework; this typically means
that it adds objects to the display
list or otherwise interacts with
visible object.
... they go on to say
If your module does not include any
framework code, you can create a class
that extends ModuleBase. If you use
the ModuleBase class, your module will
typically be smaller than if you use a
module based on the Module class
because it does not have any framework
class dependencies.
Very cool, thanks everyone. Yes, I've read those comments as well. As I've worked with Flex modules over the past couple months I believe my original interpretation was fairly close "...Adobe provided ModuleBase so that developers could extend from the minimal amount of code necessary to just get something loaded into the vm at runtime." I feel that the doc's explanation is too general though. For example I have several ModuleBase classes that "interact with the framework". They are not visual components themselves - but utilize various framework classes to fulfill a kind of service role in my applications. I think that a more accurate description of ModuleBase would be to say that "If your module is not a DisplayObject then extend from ModuleBase".
ModuleBase is for non-flex modules.
Module is for flex based modules. If you're using any flex components inside your module, this is for you. Or if you intend to use the module inside a flex app, you probably want this as well.
According to a comment inside of the ModuleBase.as file:
The base class for ActionScript-based dynamically-loadable modules. If you write an ActionScript-only module, you should extend this class. If you write an MXML-based module by using the <mx:Module> tag in an MXML file, you instead extend the Module class.
... and within Module.as:
If your module does not include any framework code, you can create a class that extends the ModuleBase class. If you use the ModuleBase class, your module will typically be smaller than if you create a module that is based on the Module class because it does not have any framework class dependencies.
So basically, if you are writing an MXML component, or if you are using flex framework classes, then you should use the Module class. Otherwise, ModuleBase is more appropriate.

How about using FLEX 3 component inside Flash file?

Is it possible to use Flex 3 component/code inside Flash (cs4) SWF file ?
I know its possible in the opposite direction.
With my minimal testing it seems you can't use Flex components when building a "pure AS3" project. (Can we start calling it PAS3 or something? Like "passé". Or "pastry". :)
I did this admittedly limited testing by creating a test project with one AS class as the "document class", which would instantiate and addChild one mx.controls.Button. I copied the whole mx package from the path mentioned by hasseg into the project source path.
This is what I found out:
By removing the use of mx_internal from a certain Version.as file, I got Flash IDE to compile my test project without warning. Nothing showed up on the stage though.
Using Flex Builder (and the flex compiler, obviously) I also managed to compile the project without errors. I put breakpoints in the code and watched it build itself in the debugger. The components were instantiated flawlessly, but still nothing showed up on the stage. This swf also crashed the browser numerous times.
I haven't used Flex code in a "pure AS3" project myself, but I don't see why you couldn't do that.
You can download the Flex SDK and get the Flex components from there, both as an swc file (under /frameworks/libs) and as AS3 source code (under /frameworks/projects/framework/src).
It looks like this can be done after all: http://labs.wichers.nu/2007/12/25/using-flex-compiled-code-within-flash/
In general you need to use MXML to initialise the Flex framework and use Flex components.
Mike Chambers from Adobe says:
There is not support for using the Flex Framework in an AS only project. While it is theoretically possible, you would have to manually bootstrap a lot of the application initialization code that Flex handles (something which would be rather complex). - Source
To see how complex, you can tell the compiler to keep the intermediate AS3 files that it generates from the MXML. Open your AS3 project properties and set -keep-generated-actionscript as an argument to the compiler. Compile your project then look in the obj/generated folder. Using Flex 4, I get 13 small files the main of which extends spark.components.Application and overrides a few methods.
So it's possible but you probably wouldn't want to do it. Flex is meant to make your life easier, not harder.

Trouble linking SWC file

I am trying to link the as3corelib library to use their JSON functionality following this tutorial. But am having trouble compiling it. My command looks like:
mxmlc --strict=true -library-path+=as3corelib.swc --file-specs myapp.mxml
But I am getting this error:
_divided_mx_managers_SystemManager.as(13): col: 14 Error: Interface method getVisibleApplicationRect in namespace mx.managers:ISystemManager not implemented by
class _divided_mx_managers_SystemManager.
public class _divided_mx_managers_SystemManager
What is the problem?
Update: Is this because I am using Flex 3? The tutorial seems to be for Flex 2. If so, what do I need to do for Flex 3?
I found an older version of the library bundled with some tutorial which worked. Submitted a bug report to as3corelib, of course I am not entirely sure how valid the bug is.
If you are using Flex Builder 3 you can actually just take the swc file and put it in the libs directory. This will automatically add it to your classpath and you should be able to use it from then on. You may need to subsequently do a clean on the project to make sure it takes it in though.
I faced a similar issue in Flex builder 4. I had to put the as3corelib sources into my source code for it to work alright.
Are you using the flex Gubmo sdk?
Looks like the method it's complaining about is in an interface that's part of Gumbo.
If so, then as3corelib probably won't work with it.

Resources