I am embedding a flash file in my flex file and then trying to add it to the stage. IU try addChild to a canvas element and to a container element, but it keeps giving me the error, the symbol "m开发者_开发知识库yBtn" is cannot be converted to a IUIcomponent.
I understand that I need to place everything inside some sort of component, but what is the proper way to do this in flex?
Adding to rawChildren isn't the way to go here. Containers ignore rawChildren
when doing things such as layout, measurement, etc.
Instead, simply wrap it in a UIComponent:
[Embed(source="...")]
public var someSwf:Class;
public function addSwf():void
{
var swf:Sprite = new someSwf();
var wrapper:UIComponent = new UIComponent();
wrapper.addChild(swf);
this.addChild(wrapper);
}
Look here for info on Embedding swf files and embedding swf symbols.
I figured it out thanks to this post: http://craiggrummitt.blogspot.com/2007/11/how-to-add-children-in-flex.html
you use something called rawChildren. so I would do myComponent.rawChildren.addChild('mymc');
Here you can downlod a complement to conver a symbol into a flex component from Flash
www.adobe.com/go/flex_ck_en
You can add all your move into a symbol then convert to flex component
Select the symbol from the libary then go to:
Commands > Convert Symbol to Flex Component
then import the swc resultant in flex
finally add the elemento into flex:
public var swfImported:NameOfTheSymbol=new NameOfTheSymbol();
private function init():void{
stage.addChild(swfImported);
}
精彩评论