Have you ever needed to access from host swf to loaded swf's methods and properties?
If you did, than you probably experienced this kind of compile time error:
Error: Call to a possibly undefined method over through a reference with static type flash.display:DisplayObject.
So here is a short tutorial on how to accomplish desired results without errors.
Let say, we have two swf files. First one is called "banerLoader" and the other "banner".
"bannerLoader" is loading "banner" swf. After load completes, "bannerLoader" needs to access methods and properties inside "banner" swf.
There are three possible solutions:
- "banner" should extend MovieClip class (in most cases it does)
- "banner" should implement interface with methods and properties you want to access
- "bannerLoader" should declare variable that can accept any type (var _banner:*) to which we asign "loader.content" value;
In first case, "banner" extends MovieClip class which is dynamic class which means that we can cast "loader.content" inside "bannerLoader" to MovieClip and than access methods and properties we want.
In the second case, "banner" implements interface with method and properties we want to use after which we can cast "loader.content" inside "bannerLoader" to interface and than access methods and properties we want.
NOTE - "banner" and "bannerLoader" must use interface with the same signature.
In third case, which is the easiest one, we only have to declare variable with no type (var _banner:*) in "bannerLoader" and to assign to it "loader.content". Than through a "_banner" variable, we can access properties and methods.
var _banner:* = loader.content; _banner.methodInLoadedSWF();