How can I know what symbols are available within a .swf?
I know nothing about Flash Professional, but a friend has given me a .swf that supposedly contains some graphics that he wants imported into a Flex program - which I know a fair bit about.
I have the .swf, but I have no idea what to put for "symbol". My friend 开发者_运维知识库doesn't seem to know what I'm talking about. How can I determine the symbol name to put in the 2nd parameter of the embed?
[Embed(source='SomeSwf.swf', symbol='WhatGoesHere??')]
Is there some way to browse the .swf, or some way to just import the whole thing and step through the symbols in actionscript?
Thanks In Advance.
You should specify the Linkage name of the symbol as the 2nd parameter. To set up Linkage name your friend should select symbol from Library panel, open its properties, and select "Export for Actionscript" checkbox, specify class name (if needed):
Class name specified in this panel is the 2nd parameter you should use to embed that object. After publishing swf you'll be able to instance that symbol object this way:
public class EmbedTest extends Sprite
{
[Embed (source = "square.swf", symbol="Square")]
private var swfAsset:Class;
public function EmbedTest():void
{
var embeddedSwf:*=new swfAsset();
addChild(DisplayObject(embeddedSwf));
}
}
UPD1:
Is there some way to browse the .swf, or some way to just import the whole thing and step through the symbols in actionscript?
You may try to step through all on-stage symbols of the embedded swf this way:
package
{
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.utils.getDefinitionByName;
[SWF(backgroundColor="#FFFFFF", width="1000", height="400")]
public class EmbedTest extends Sprite
{
[Embed (source = "yourSwf.swf")]
private var swfAsset:Class;
public function EmbedTest()
{
super();
var embeddedClip:Sprite=new swfAsset() as Sprite;
var loader:Loader=Loader(embeddedClip.getChildAt(0));
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadCompleteFunction);
}
private function loadCompleteFunction(e:Event):void {
var loaderInfo:LoaderInfo=e.target as LoaderInfo;
var content:MovieClip=loaderInfo.loader.content as MovieClip;
for (var i:int=0; i<content.numChildren; i++) {
var embeddedMovieClipChild:*=content.getChildAt(i);
trace (embeddedMovieClipChild.name, embeddedMovieClipChild);
}
}
}
}
UPD2: Also consider adding assets to your project as swc files. http://blog.geewa.com/post/2009/03/16/Integrating-Flash-Professional-and-Flex-Builder-Using-SWC.aspx
Because of the way flex embeds that data you will need to know the symbol names when they are embedded. To do this, you'll need the .fla file.
If you only have the swf, you can try decompiling it to get the names - but they will need to have been linked for export (so they might not even have them!). In which case, you'll probably want to suck it into flash and then name them and flag for export them yourself in another swf.
Hassle. Best bet is to get your friend that gave you the swf to either give you the names of the assets or the .fla file.
=)
You can try to browse the swf in FlashDevelop, which has a SWF exploration feature. If you use the Project side panel in FlashDevelop to navigate to the swf, you can open it up to see the names of the Classes, Symbols and Fonts within it. But the Symbols you see will only be the ones that have a Symbol name already though; if it was unnamed it might get a funny name like instance2143 which won't be listed.
Actually there is a way to load list of available definitions dynamically.
There is a class called SWFExplorer that can give you the ability to do so.
Everything is explained here: http://www.bytearray.org/?p=175
You need to create a project, create the class called for example "SWFReader" that traces out list of names you need.
精彩评论