views:

31

answers:

1

I have two SWFs: main.swf and external.swf. main.swf needs to access some methods in external.swf, so it loads external.swf into itself and uses getDefinitionByName("package.Class") to access the class and one of its methods:

var ExternalClass = getDefinitionByName("package.Class") as Class;
var ClassInstance = new ExternalClass();
var NeededFunction:Function = ClassInstance["NeededFunction"] as Function;
var response:String = NeededFunction(param);

Now, I need to extend the functionality of NeededFunction (which is a public method)... I know it's possible to override public methods, but how would I go about this with a dynamically loaded class?

I was thinking I could do something like this, but it doesn't work:

var ClassInstance["NeededFunction"] = function(param1:uint):String { 
    var newString = "Your number is: "+param1.toString();  //New functionality
    return newString;
}
A: 

Another way to deal with this could be to have the classes in a package that's accessible by both SWFs. Just add the classes' root folder to your Actionscript path .

Instead of getting a class by using getDefinitionByName , you simply import it. As for overriding , you can create a Class that overrides one of the classes , or you can create an Interface.


import com.yourlocation.ExternalClass;

var external:ExternalClass = new ExternalClass();

PatrickS
Unfortunately, I don't have access to the SWF's classes or I would have done what you suggested long ago. The method I need to extend is from a proprietary SWC library, so I can't modify the SWC unless I attempt to disassemble it, which I don't intend to do.
lefthandpath
This article may help:http://www.airtightinteractive.com/2009/06/better-flash-asset-loading-using-swcs/
PatrickS