actionscript-3flash-ccrsl

Is it possible to put a Class linked to a document (aka Document Class) into a RSL and still have it as Document Class?


Firstly, my environment. My question is if it's possible to do so using Flash Professional and not Flex, FlashBuilder or the like (I don't have those environments at the moment).


Here is the thing: we have several .fla files with a Document Class set. The .as file with the class is shared with all those .fla files, so all them have this same class set as their Document Class. The point is that because of that the Class is compiled into each generated .swf files, and as result any changes made to the Class would require all the .fla files to be recompiled.

After some research I found out about RSLs. But I'd like to know if it's possible to have the class as RSL while also having it as Document Class for each file? It would ease stuff because in case a change needs to be done in the class we wouldn't need to recompile each file, or regenerate each .swf files.

Aditionally, if it's possible, how could I implement a RSL through Flash Professional? All the documentation I have found shows that through Flex and others.

Please let me know if I wasn't clear enough.


Solution

  • As already pointed out, you cannot use a RSL with a document class. However, you can put classes in an RSL and load those at runtime likely achieving what you desire.

    Here is a very simple example:


    1. Create the RSL assets:

    Let's say you have a class that changes from time to time and you want to load it's functionality at runtime:

    //TestyMcTestFace.as
    package  {
        public class TestyMcTestFace {
            public static function go():String{
                return "I'm Testy McTestFace";
            }
        }
    }
    

    So, what you can do, is make a new AS3 project in FlashPro/AdobeAnimate CC. Link up your class file so your project finds it (in this case I just put my TestyMcTestFace.as in the same directory as the new .fla I created).

    Put a reference in the timeline code to the class(es) you want included. Without this reference the class will not get exported in the resulting swc/swf.

    So for this case, I have a new AS3 project with just one line on the first frame of the timeline:

    TestyMcTestFace;
    

    Now, go to your publish settings, and make it so only Flash (swf) and SWC are checked.

    Publish this new project (you now have a swf/swc you can use as a RSL for other applications).

    2. Setup your other applications to use the swf/swc as a RSL.

    In your existing flash project, go to the 'Advanced Actionscript Settings' (click the wrench icon next "Actionscript 3.0" in the publish settings).

    Click the library path tab, click the plus button, then click the "Browse To SWC File" button (currently it's an icon with the flash 'f' in it). Find your swc file from the previous step.

    Now, with your new entry highlighted, click the info icon (linkage options). Change it from "Merged into code" to "RSL". Then add a path to the swf file (where it will be when this application runs).

    Now, in your application, you can reference classes from the RSL. So if we do this:

    trace(TestyMcTestFace.go());
    

    You should get the output "I'm Testy McTestFace".

    FlashPro will automatically load the RSL for you. Be aware though, that if you aren't letting flash preload your app automatically, it won't be available right away.

    If you changed and re-exported the swc/swf from step one, those changes should be reflected when you run your existing swf again (no recompiling necessary).


    Caveats:

    Be careful with code in RSL's. It's easy to get clashing classes. As a best practice, only put code that is completely standalone/de-coupled into RSL's. Code that has lots of imports should be avoided. It's also best if you don't reference classes with same names in your compiled swf's that you are loading the RSL's.

    Also keep in mind that RSL's can have sanbox/security restrictions if not coming from the same domain.