Can't inherit classes defined in RSL?

Note. This is an ActionScript project, not a Flex project.

I have a class A defined in RSL (technically, this is an art resource that I made in the Flash IDE and exported for actionscript. Then the entire .FLA was exported as SWC / SWF).

In my main project, I have a class B that inherits from class A. The project compiles fine, with no errors.

However, when the project is executed and I try to create an instance of class B, I get a validation error. However, instantiating a class A is very simple:

import com.foo.graphics.A;   // defined in art.swf / art.swc
import com.foo.graphics.B;   // defined locally, inherits from A
...
<load art.SWF at runtime>
...
var foo:A = new A(); // works fine
var bar:B = new B(); // ERROR!
// VerifyError: Error #1014: Class com.foo.graphics::A could not be found.

For reference, here is how I load RSL:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onArtLoaded);
var request:URLRequest = new URLRequest("art.swf");
var context:LoaderContext = new LoaderContext();
context.applicationDomain = ApplicationDomain.currentDomain;
loader.load(request, context);

Class B is defined as follows:

import com.foo.graphics.A;
class B extends A {}
+3
source share
1

, . .

, B. , swf . . , , :

var bar:B = new B(); 

var bar:B;

.

, swf, - , A (B parent) swf. mxmlc:

-compiler.external-library-path "lib.swc"

, :

-compiler.library-path "lib.swc"

. , , main.swf( , , , ).

, lib , , IDE .. B A. , A , B . .

Flash IDE, , " ". , , , , . Flex . swf, , , ( ) . , .

, RSL , , RSL ( RSL ). , RSL ( "": URL-, .. , RSL , , , Flash Flash 6 , RSL ( , ), .

( RSL ) shell.swf, art.swf . code.swf, art.swf , com.foo.graphics.A ( art.swf), com.foo.graphics.B ( .swf).

    public function Shell()
    {
        loadSwf("art.swf",onArtLoaded);
    }

    private function loadSwf(swf:String,handler:Function):void {
        var loader:Loader = new Loader();
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, handler);
        var request:URLRequest = new URLRequest(swf);
        var context:LoaderContext = new LoaderContext();
        context.applicationDomain = ApplicationDomain.currentDomain;
        loader.load(request, context);              
    }

    private function onArtLoaded(e:Event):void {
        loadSwf("code.swf",onCodeLoaded);
    }   

    private function onCodeLoaded(e:Event):void {
        var li:LoaderInfo = e.target as LoaderInfo;
        addChild(li.content);

    }

:

        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);

( ) init, .

, , , .

, , .

    private var _symbol:MovieClip;

    public function B() {
        var symbolDef:Class = ApplicationDomain.currentDomain.getDefinition("com.foo.graphics.A") as Class;
        _symbol= new symbolDef();
        addChild(_symbol);
    }

com.foo.graphics.A - , . , x, y, width .. .., -, . , /, - (com.foo.graphics.A).

:

public class MovieClipProxy extends MovieClip {

    private var _symbol:MovieClip;

    public function MovieClipProxy(linkagetName:String) {
        var symbolDef:Class = ApplicationDomain.currentDomain.getDefinition(linkagetName) as Class;
        _symbol = new symbolDef();          
        addChild(_symbol);
    }

    //  You don't actually need these two setters, but just to give you the idea...
    public function set x(v:Number):void {
        _symbol.x = v;
    }

    public function get x():Number {
        return _symbol.x;
    }
}

public class B extends MovieClipProxy {

    public function B() {
        super("com.foo.graphics.A");
    }


}    

, ( ) , .

, B , , , . , , , , , , . , .

PS

, :

public class B extends MovieClip {

    private var _symbol:MovieClip;

    public function B() {
        _symbol = new A();
        addChild(_symbol);
    }

}

:

public class B extends MovieClip {

    public function B() {
        addChild(new A());
    }

}

, , , .

+2

Source: https://habr.com/ru/post/1751501/


All Articles