1
votes

I'm trying to load a RSL library into a flash animation developed with Flash CS5 IDE, that extends a custom class and implements an interface. I have reduced the problem to the simplest setup and find that I can have my main class extend another class or implement an interface, but not do both at the same time if I want to load an RSL.

I have a very simple class to extend:

import flash.display.Sprite;
public class MySprite extends Sprite 
{

    public function MySprite() 
    {

    }
}

The main class with TestSymbol which is a symbol from the RSL library:

import flash.display.Sprite;
public class MainApp extends MySprite implements ITest
{
    public var bug:TestSymbol = new TestSymbol();

    public function MainApp() 
    {
        addChild(bug);
    }
    //To meet interface requirements
    public function test():void {

    }
}

}

and a very simple interface

    public interface ITest 
{
    function test():void
}

The RSL library is a very simple one too - just one symbol with a square drawing. It is specified in the actionscript settings. Everything runs well if I change the MainApp class to:

public class MainApp extends MySprite

or

public class MainApp extends Sprite implements ITest

but if I want both I get the VerifyError: Error #1014 with MySprite not found and ReferenceError: Error #1065.

Any ideas?

2

2 Answers

1
votes

I had the same problem. Actually it will continue with this error even if you are extending from a class in RSL which implements an interface from RSL. It looks like the rsl needs some time to load and be interpreted by the player. If you would use in a second frame classes or interfaces encapsulated in the rsl they will work fine. How so ever they are not working fine in the first frame.

My solution, related to my case was: 1) Main application using external lib rsl.swf. 2) A module application having main document class ModuleBase implementing IModule both encapsulated in rsl.swf, so module application was using also the extaernal lib rsl.swf. 3) Main application was loading module application and casting it to ModuleBase.

It looks like time needed by Main application to load module application swf it is enough to initialize/register types inside rsl.

Howsoever inside Flash IDE: 1) testing the module application, which has main document of a type extending ModuleBase, exposed by rsl, will end in the VerifyError: Error #1014 2) compiling the module application works just fine 3) compiling and testing the main application works just fine

Inside browser: 1) testing the module application is failing with VerifyError: Error #1014 2) testing the main application works fine

So my solution is to compile modules extending some external class and use them inside an application which has the RSL types already available.

I hope this will help somebody.

//RSL

package interfaces {
    public interface IModuleFactory
    {
      //...
    }
}

package app.models {
    import interfaces.IModuleFactory;
    public class ModuleBase extends MovieClip implements IModuleFactory
    {
      //...
    }
}

//Module

package {
   import app.models.ModuleBase;
   // main document class
   public class Module extends app.models.ModuleBase
   {
      //..
   }
}

//somewhere inside Main application

protected function onModuleLoaded(event:Event):void
{
        var lInfo:LoaderInfo = event.currentTarget as LoaderInfo;
        setTimeout( function(){ extractFactory(lInfo); },200);

}

protected function extractFactory(lInfo:LoaderInfo):void
{
    if( lInfo )
    {
        if( !(lInfo.content is ModuleBase) )
        {
                trace(lInfo.content ,' is not ModuleBase');
        }

        var m:DisplayObject = lInfo.content;
        if( !(m is IModuleFactory) )
        {
                trace(m ,' is not IModuleFactory');
        }
        if(m)
        {
            var factory:Function = (lInfo.content as IModuleFactory).factory;
            if( null != factory)
            {
                factories[key] = factory;
                trace('module loaded',m,key);
                dispatchEvent(new Event('moduleloaded'));
            }else{
                trace('could not get a reference to module factory!');
            }
        }else{
            trace('could not cast to ModuleBase');
        }

    }else{
        trace('could not get a reference to a LodearInfo!');
    }
}
0
votes

Thank you for explaining this. Your scenario seems slightly more complex with the module extending and implementing from RSL. In my case (the module class MainApp implements and extends non-RSL class/interface and just uses a class from RSL as a variable). Implementing the interface by a parent (like ModuleBase) class instead of the Module class works well. It doesn't even give me an error when testing in Flash IDE.