2

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.

Shadow
  • 29
  • 1
  • 9

2 Answers2

1

not possible, RSL is only meant for runtime sharing not for compile time sharing which you need to access the class.

First thing is, one class is not that much in term of size so there's not really a need to make it unique a sharable between swfs.

Now you affirm that all swfs would have to be recompiled if you make any change but that's not actually accurate since only one class definition can exist in one given runtime. The first swf running is by default the one loading the class definition, all the loaded swfs following would have their class definition discarded by default so no you don't have to recompile them in theory.

So to resume yes you have to recompile all swfs if you make major changes to the class but not for minor changes. But that situation is symptomatic to your app design which might not be the most efficient and logical.

BotMaster
  • 2,233
  • 1
  • 13
  • 16
  • Thanks for the answer! Just a little clarification about my case. What I have isn't a swf loader that loads the other files, they are all separated and individual .swf files that are used individually into another application (through ActiveX). The shared .as file is more then that all the files use the same base code, then the class defined as Document Class ends to be compiled into each file, that's why I said that if a change is made all files need to be recompiled. What I'm looking is kind of an implementation like a dll, just to make shared code easier, it's not about size actually. – Shadow May 20 '16 at 20:44
  • The compiled code (swc) won't be of help in that case either since it's only used at compile time. No solution that I can see here. – BotMaster May 20 '16 at 21:07
  • Hmm ok, I got it. Thanks. – Shadow May 23 '16 at 13:39
1

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.

BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40
  • How does this relate to document classes or to the question at hand? Lot of typing for nothing. – BotMaster May 21 '16 at 03:12
  • Thanks for the answer, it also shed some light on my doubts. So maybe the closest approach I could use is splitting my main class then I could spread functionality to RSLs, also making like a main loader .swf with the main class and load all other files through that? The main point I want to achieve is sharing code. – Shadow May 23 '16 at 11:54
  • Yes, it's best to encapsulate your functionality into many classes anyway (separation of interests) so the best architecture would be to have all your common code in self contained classes (that can be used with RSL as per my answer) and only have your document class contain code specific to that application – BadFeelingAboutThis May 24 '16 at 04:54
  • Ok, that seems to be the approach to take. It's just that it's not a code made by me and the original author put all the stuff into a single .as file. Thanks. Although both answers have answered my question, this one went beyond and showed me a path to follow. – Shadow May 24 '16 at 14:53