views:

2055

answers:

4

Hi. I want to be able to load an swf into a flex 4 application in order to use it's 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 the issue ?

+1  A: 

this.rawChildren.addChild( ldr ) should work

Barod
A: 

Did you find an answer to this problem? I have been trying to do exactly the same type of thing and cannot get it to work. The suggestion above of rawChildren.addChild does not compile for me either.

AVSESIS
thanks for alerting me that rawchildren did not work. i added an answer, hopefully it will suite your needs.
ufk
+1  A: 

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();
    }
}
} 
ufk
+1  A: 

just create another container wich u place 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 );

frictionman