0
votes

I have a MovieClip in Library , which I am loading dynamically through addChild method.

The problem I am facing is :--

I have a Main Class which runs with several other classes and several FLA's.

Main Class calls a sub class function which in return calls the code in a frame of a FLA which loads this object from Library.

This object is not present in all FLA's, thats where I am getting stuck, getting Compile time error.

Tried checking through this but failed :(

var classExist:Boolean = isClassExists("CTRL_ALARM");

function isClassExists(className:String, domain:ApplicationDomain = null):Boolean { var res:Boolean;

if(domain)
{
    res = domain.hasDefinition(className);
}
else
{
   // res = getDefinitionByName(className);
    //or the same
   res = ApplicationDomain.currentDomain.hasDefinition(className);
}
trace(res);
return res;

}

Is there any way I can duplicate objects on Stage in as3, or how can I restrict an object from being compiled if it is not present in Library?

1

1 Answers

0
votes

Try the following. If all of your SWFs are in the same sandbox, it might just work:

import flash.utils.getDefinitionByName;

var AlarmClass:Class = getDefinitionByName("CTRL_ALARM");
var anAlarm:DisplayObject = new AlarmClass;

Then, to make it work even with sandbox restrictions, you may seek for the definition you want through the loaded SWFs:

// This should contain Loader objects with your loaded SWFs.
var aList:Array;

for each (aLoader:Loader in aList)
{
    // Get reference to loaded app domain.
    var aDomain:ApplicationDomain = aLoader.contentLoaderInfo.applicationDomain;

    // Check if such a class is in that SWF.
    if (aDomain.hasDefinition("CTRL_ALARM"))
    {
        var AlarmClass:Class = aDomain.getDefinition("CTRL_ALARM");
        var anAlarm:DisplayObject = new AlarmClass;

        break;
    }
}