ask question
Click here to ask Question Now Its free No registration required. Flash, Flex, Flash Media Server, ActionScript,Adobe Air. Most questions receive a response in an hour.
Rob Chisholm

9/9/2010 8:39:58 PM

Title: Accessing runtime shared libraries, crossdomain & security

Preface: I'm using Flash CS4 Professional for the Mac, AS3 and Flash Player 10.

I have an RSL (runtime shared library) SWF that contains bundled classes which I store in an online location.
I also have another SWF that access that runtime shared library in order to instantiate it's classes and use their methods/functions.

Here's the code of the RSL:
[CODE]package {
import com.thisCompany.customClassOne;
import com.thisCompany.customClassTwo;
import flash.display.Sprite;

public class MyRSL extends Sprite{
public function MyRSL() {
trace("MyRSL loaded");
[/CODE]Here's the code of the accessing SWF:
[CODE]package {
import com.thisCompany.customClassOne;
import com.thisCompany.customClassTwo;
import flash.display.*;
import flash.net.*;
import flash.system.*;
import flash.events.*;

public class MyTemplate extends MovieClip{
// The instance variables for the classes from the RSL need to be declared as generic objects since AS doesn't recognize them yet
// because they haven't been loaded. However, when including them at compile time, you can associated them with their class names
private var classOne:Object;
private var classTwo:Object;

public function MyTemplate() {
// Load the runtime shared library (RSL) first to import our classes
var RSLLoader:Loader = new Loader();
// Create a listener for the INIT event so we know when the RSL is loaded and can then instantiate our classes
RSLLoader.contentLoaderInfo.addEventListener(Event.INIT, RSLInitListener);
// here's the relative URL that tells the accessing SWF to look in the same directory for the RSL - disabled in this example
//RSLLoader.load(new URLRequest("./MyRSL.swf"), new LoaderContext(false, ApplicationDomain.currentDomain));
// here's the absolute URL of the RSL that doesn't seem to work properly - it loads properly but I can't access the classes
RSLLoader.load(new URLRequest("http://some.domain.com/myRSL.swf"), new LoaderContext(false, ApplicationDomain.currentDomain));

private function RSLInitListener (e:Event):void {
trace("RSL initialized");
// Runs when runtime shared library is loaded and initializes
// Initialize each class from the RSL. Once initialized, you can then call methods from that instance of that class.
classOne = new customClassOne();
classTwo = new customClassTwo();

private function init():void{
// Default initialization function

Now, the publish setting's (Actionscript 3.0 setting's) External library path on the accessing SWF's FLA file is ./MyRSL.swc, indicating that the SWF should look in it's local directory for the SWC. I've also had other relative URL's work for this as well, such as ../RSL/MyRSL.swc. That's not a problem (although I really wish I could store that SWC online as well and use an absolute URL for people to access it, similar to how you include Javascript libraries and such...).

The problem is with the loading location of the RSL (SWF). It works if I use a relative location for it... it loads fine, classes run, functions/methods run, etc... all peachy.
But if I specify an absolute URL for the RSL and the host SWF is used outside of that domain (another domain or on the local computer), I can't access the classes, although the RSL SWF does load completely, run and initialize, running it's constructor and any methods called within that constructor.

So I've narrowed it down to a cross-domain issue. But even after including a crossdomain.xml file in the same directory online as the RSL SWF, I still can't access the objects inside that loaded RSL SWF.

Here's my crossdomain.xml file:
<site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*" to-ports="*"/>

I've also tried putting the code Security.allowDomain('*') (from import flash.system.Security) in the RSL SWF and it doesn't work.

Can somebody tell me what to do to let my my host SWF properly access the objects and methods/functions of my RSL in another domain?


Points: 380
9/9/2010 9:01:44 PM

By default flash player try to load crossDomain from root of domain so it should be like

Post your Reply


Type your Reply or Answer

Are you human? What is 1+14+4 

Members Login

Forgot Password

This website focus on: Flash | Flex | FMS | RED5 | WOWZA | Flash Media Server | Adobe AIR | ActionScript,Flash Solutions | Flash Question | Flash Answers | Flash Developers | Flash Problem, Flash Help, Flash bugs, Flash workaround | Flash Blog | Flex Question Answers | Flash Forum | Flex Development | Actionscript development | Flash development | Adobe AIR development
Copyright © 2008 AskMeFlash.com. All rights reserved. Privacy Policy | Terms & Conditions