Adobe Flash Builder (flex4): addChild() is not available in this class.

陌路散爱 提交于 2019-11-29 09:04:07

问题


I want to load an swf into a flex 4 application in order to use its classes.

var ldr:Loader=new Loader();
ldr.load(new URLRequest("file://path/to/fileswf"));
ldr.contentLoaderInfo.addEventListener(Event.INIT, loaded);
function loaded(evt:Event):void { addChild(ldr); }

I receive the error:

Error: addChild() is not available in this class. Instead, use addElement() or modify the skin, if you have one.
at spark.components.supportClasses::SkinnableComponent/addChild()[E:\dev\gumbo_beta2\frameworks\projects\spark\src\spark\components\supportClasses\SkinnableComponent.as:966]
at main/private:init/loaded()[C:\Documents and Settings\ufk\Adobe Flash Builder Beta 2\xpogames-toolkit-test\src\main.mxml:22]

If I change addChild() to addElement(), I receive the following compilation error:

1067: Implicit coercion of a value of type flash.display:Loader to an unrelated type mx.core:IVisualElement. main.mxml path/dir line 22 Flex Problem

Any ideas how to resolve this issue?


回答1:


Create another container to place the displayObject in:

// container ( IVisualElement ) for DisplayObjects
var container:UIComponent = new UIComponent();
addElement( container );

// displayObject goes to container
var displayO:Sprite = new Sprite();
container.addChild( displayO );



回答2:


well in flash builder 4 full version, there isn't any this.rawChildren.

The best approach to resolve the issue would be to convert each required class to a flex component and to use it on your flex application:

  1. download and install flex component kit http://www.adobe.com/cfusion/entitlement/index.cfm?e=flex_skins

  2. create a movie clip

  3. convert to flex component

  4. add the relevant functions to this class

a skeleton for a class that is attached to a movieclip that is about to be converted to a flex component:

package {
import mx.flash.UIMovieClip;
import flash.text.TextField;
import flash.events.Event;
import flash.events.MouseEvent;
public dynamic class challenge_screen extends UIMovieClip {

    public function challenge_screen() {
        super();
    }
}
} 



回答3:


private var _loader:SWFLoader = new SWFLoader();
private var _uicomponent:UIComponent = new UIComponent();
private function swfLoaded(event:Event):void 
{
Alert.show("inside swf Loaded");
var content:DisplayObject =_loader.content;
_uicomponent.addChild(content);
} 
public function loadSWF () : void 
{   

_loader.addEventListener(Event.INIT, swfLoaded);
_loader.load("http://intelliveysoft.com:5080/myelearn/Admin.swf"); 
addElement(_uicomponent);
}

Try this. It will work




回答4:


this.rawChildren.addChild( ldr ) should work



来源:https://stackoverflow.com/questions/2023632/adobe-flash-builder-flex4-addchild-is-not-available-in-this-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!