View Full Version : [AS3] importing fl.controls package
08-06-2007, 06:17 PM
I'm trying to use some of the CS3 Flash components in a pure ActionScript 3 project. However, I can't seem to figure out how to import those "fl.controls" packages.
I'm using Flex Builder 2, but again, not actually any Flex, just ActionScript. I tried adding the following folder as an SWC folder in the project's library path:
C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\Components\User Interface
That seems like the correct thing to do, however Flex Builder 2 reports these errors:
An internal build error has occurred. Please check the Error Log.
unable to load SWC Accordion.swc
08-06-2007, 06:47 PM
the fl components are FLA-based. You will need to publish them through a FLA. I am not of aware of anyway to do it otherwise.
08-06-2007, 06:56 PM
Hmmm, it does look like I can grab an instance of one of these controls out of an externally loaded SWF file, and then presumably I could call its methods and so forth. However that seems like it would be a pretty big pain, difficult to control things like data sources programatically.
What is the best solution if I want to have an artist making UIs in the Flash tool but using them from pure ActionScript? Are there alternate sets of components that I could import into my ActionScript, or would I have to write them myself?
I know there is a set of Flex components that can be loaded into the Flash tool and used there. How much Flex would I have to do on the code side to get it to work?
08-06-2007, 07:34 PM
The fl.controls package is in a pre-compiled clip called "ComponentShim". Drag a component on stage and look in the Component Assets >> _private folder in your library. If you want to use fl.controls, just keep ComponentShim in your library with the appropriate linkage.
Since it's precompiled, you take on every other Class that is in ComponentShim which increases file size.
Found this :http://www.flashbrighton.org/wordpress/?p=31
08-06-2007, 08:23 PM
As senocular mentioned, the AS3 components in Flash CS3 are built with FLA files (not SWCs). However, if you want to use the component source code in your Flex Builder projects, it's available here (Windows, similar on a Mac):
C:\Program Files\Adobe\Adobe Flash CS3\en\Configuration\Component Source\ActionScript 3.0\User Interface
You should remember that the skin assets are still needed from the FLA files, but if you want to build custom subclasses of fl.core.UIComponent and/or do all your skinning programmatically, these files work just fine in AS-only projects with the Flex SDK. With a little bit of work, it might be possible to port the programmatic skins from the Flex components to work with the CS3 components. Obviously, you probably can't just drop them in, but it might be an interesting project to explore. :)
08-06-2007, 08:40 PM
Thank you Sleeve and dr_zeus.
To clarify what I am trying to do, I'd be happy to let the artist do all the skinning work in the Flash tool. I just want to be able to drive it programmatically. I think I understand how to grab particular instances of components from an externally loaded SWF file, and adding event handlers to them goes a pretty long way. Also, it appears I can call their methods just fine (though since I have to use untyped variables to reference them, the compiler can't catch errors, which is annoying :mad: ).
However, it seems that there are still other things in other "fl." packages I might want to muddle with. For example, I know I'll want to be able to control a DataProvider attached to a List programmatically. Through some experimentation I've found that I can do the same sort of method calling through an untyped reference on myList.dataProvider. However, since the DataProvider is defined in an "fl." package, it must be instanced and added to "myList" through action script added in the FLA. That's not an unacceptable solution, it just seems a bit clunky, and puts a burden on the artist (or somebody) to add a bit of code in the flash tool every time he creates a List.
Any recommendations on how to do this a little better? I guess I have a few ideas... I could create my own subclasses of List, etc. that automatically instance a DataProvider, or perhaps grab it from some interface I'm providing in my main program, and the artist could create his list from that. I guess I could make a dedicated "DataProvider" FLA/SWF that contained mostly just code, with a class or classes to do whatever DataProvider instancing and management I need, and load that into my main program.
I'm also not entirely clear about this ComponentShim SWC. When you say I should keep it in my library, are you talking about the library in the FLA file or in the library path of my ActionScript project? And does this only contain compiled code for the classes in the relevant components packages, or would there be some way to put other stuff in there, e.g. DataProviders so I could instance and manage them in my program independent of a particular FLA file?
08-06-2007, 09:13 PM
If you were to keep ComponentShim in your library with the linkage set to 'Export for ActionScript' and 'Export in First Frame', you can successfully import the fl.controls package and a number of others. From there, you can instantiate any of the Classes using AS alone. Like mentioned earlier, if the skins do not exists in the library and you try to instatiate a DataGrid, you'll have nothing to display on stage.
For the purpose of instantiating a DataProvider, which has no skins, the above mentioned technique will work.
08-06-2007, 09:34 PM
If you were to keep ComponentShim in your library with the linkage set to 'Export for ActionScript' and 'Export in First Frame', you can successfully import the fl.controls package and a number of others.
I'm still confused... are you talking about importing those packages in ActionScript that is written as part of a flash project including an FLA file? I'd like to be able to import it in an external AS file that is not linked to an FLA document. That's not possible, is it?
(Although... being able to do it in an AS file linked to a FLA may still be quite helpful for me.)
08-06-2007, 10:07 PM
edit: lots of strange behavior when trying to use the Component Source files, enough worth me starting a new post.
08-10-2007, 07:49 PM
I found the following post to be very informative and should help:
vBulletin® v3.8.5, Copyright ©2000-2013, Jelsoft Enterprises Ltd.