Took me two hours to discover this today with no compiler errors. Almost all documentation that is out there about ActionScript 3 is in one way or another about Flex and not Flash. I am very familiar with Flex and have been using it for about a year now, but have had to do a project in the Flash IDE using AS3. Well to my dismay, I finally learned that the [Embed] meta tag is only for the Flex compiler to interpret. Some who read this far may be saying, "um duh!". Well, I'm saying most of the documentation out there that is searched on returns Flex ActionScript 3, not Flash ActionScript 3. So this isn't the most cut and dry topic out there and the documentation is blurry and flooded with Flex topics but not really Flash CS3. I've heard from some in the ActionScript community that Flash is a dying horse. Well, If this is true please post your reasons why. See, I keep reading that Flash is still the most powerful tool around for creating rich component designs and interactions and yes they work with Flex to build RIA's. I do it all the time. So my question is this. If Flash is a dying horse for coding then take out everything except gotoAndPlay() and stop(); Leave coding for Flex and let us know definitively that Flex is the tool for development and "Thermo" that will be the newest booger stuck to the beach ball for Designer / Developers.
So if you are trying to do this below then sorry it doesn't work compiling with the Flash IDE :
package
{
import flash.display.*;
[Embed(source="library.swf", symbol="Star")]
public class Star extends MovieClip
{
public function Star()
{
trace('Star Created');
}
}
}
Instead in Flash I can either use a Symbol from the Library that is in the .Fla, use a Loader object, or use a RSL - "Runtime Shared Library". I chose to use the Loader method combined with the Symbol from the Library. For me in this very specific instance it was the best for me since I had to use Flash for this project using ActionScript 3. Now fortunately for me the Loader Object is the same for both Flash and Flex so I know my AS3 code will not die silently.
Here is the code I used that combines the Loader and a Symbol in the Library hybrid:
NOTE: This is called using the Document Class in the Flash IDE.
package {
import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;public class Main extends MovieClip {
//private var star:Star;// CONSTRUCTOR
function Main():void {
trace('MAIN INSTANTIATED');
// Externally Loaded SWF Content
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaderComplete);
loader.load(new URLRequest('assets/banner_background.swf'));
this.addChild(loader);
// Symbol in the Library
var bt:Banner_Title = new Banner_Title();
this.addChild(bt);
}
private function loaderComplete(event:Event):void {
//trace('loaderComplete');
}
}
}
So in conclusion just be aware that the [Embed] meta tag DOES NOT WORK for the Flash IDE. It is only a Flex Compiler recognized tag and will not give you any errors saying "Sorry this is not supported". And if you are wanting to code something Flash use the Document Class.
However some of the best documentation I did happen to find about this topic is listed below for you to read:
http://jessewarden.com/2006/12/integrating-a-flash-interface-into-flex-2.html
http://www.adobe.com/devnet/flex/articles/flash_perspective.html
http://www.adobe.com/devnet/flex/articles/workflows.html
http://www.adobe.com/devnet/flex/articles/flex_flash_workflow.html
http://blog.halcyonsolutions.net/2007/06/30/flex_flash_integration_resources/
http://drawlogic.com/2007/09/20/howto-using-loaders-in-as3/







6 comments:
I wouldn't have said "um duh!", but I do think the current setup is fairly reasonable. In flash you have a library into which assets can be placed for compilation into the SWF - a natural way of 'embedding', and I guess I'd be looking at compiled using clips in your case? In Flex there is no library, hence the necessity for the Embed meta - to gain access to assets.
In addition to the references you list, I'd recommend having Colin Moock's Essential ActionScript 3 to hand while you programme. It is not biased to Flex. It does describe Embed and Loaders very well. It also suggests that [Embed] might make it to Flash in the future.
I don't know if this helps or hinders, but since I use the command-line compiler to create my Flash swfs, following this example :
http://www.senocular.com/flash/tutorials/as3withmxmlc/
you will find that indeed you can use the [Embed] meta tag for a Flash application.
I am in the same boat with TerryCorbet, I have no problems embedding anything without Flex. I use the free Flex3 SDK and don't know jack about Flash CS3.
I was thinking about getting CS3, but after hearing about it's limitations, I'll probably stick with my free cobbled together solution. Hopefully they will have it all together for CS4 ( and include Flex Builder in the Web Design CS4 )
Dude, I'm doing an AS project in FB3 and the Embed tag works fine but only allows me to make Sprites ... it doesn't want to cast to MovieClips. Pants.
Frankie Loscavio
"I've heard from some in the ActionScript community that Flash is a dying horse. "
I have heard this as well.
While I do believe that Adobe has this intention. I wholeheartedly disagree with it.
http://www.flashkeep.com/node/59
If flash was a dying horse, then why are they continuing to develop new versions of the Flex SDK and making announcements of developing a flash player compatible with the iPhone/iTouch?
Why would they release the new Flash Player 10?
Post a Comment