Skip to main content
June 25, 2011
Question

How to access instances of loaded SWF?

  • June 25, 2011
  • 3 replies
  • 831 views

Hello all!

I'm not a developer, I'm just trying to create my small personal website, so I ask your forgiveness in advance if my question sounds stupid...

Well, I need to get access to MovieClips instances in my external SWF file, which is a player skin.

Although there are plenty tutorials in the Internet about this (e.g. http://www.demetri-media.com/FlashTalker/ExternalSWFCommunication.html), I'm unable to make them work for me...

Here is my code:

import flash.display.Loader;
import flash.events.MouseEvent;
import flash.display.MovieClip;

const SCALE:Number = 1.25;
var CPLoader:Loader = new Loader();
var ControlPanel:MovieClip;

addChild(CPLoader);
CPLoader.load(new URLRequest("ControlPanel.1920.swf"));
CPLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loading_complete);

function loading_complete(event:Event):void
{
ControlPanel = CPLoader.content as MovieClip;
ControlPanel.scaleX = SCALE;
ControlPanel.scaleY = SCALE;
ControlPanel.x = - (ControlPanel.width - stage.stageWidth) / 2;
ControlPanel.y = stage.stageHeight - ControlPanel.height;
ControlPanel.Power_BTN.addEventListener(MouseEvent.CLICK, hereWeAre_handler); // Power_BTN is one of the buttons in my external SWF
}

function hereWeAre_handler(event:MouseEvent):void
{
trace("Got it!");
}

When I launch my application I get Error #1069: Can't find property Power_BTN in ControlPanel_fla.MainTimeline__Preloader__; there is no default value.
at Experimental_fla::MainTimeline/loading_complete()

Any help will be appreciated...

This topic has been closed for replies.

3 replies

June 26, 2011

I realised why ProLoader shifted the loaded content right.

Apart from Loader, ProLoader just ignore 'stage' of loaded external SWF. So, the ControlPanel.width was not the width of the stage in external SWF but the distance between the left side of extreme left MovieClip and the right side of extreme right MovieClip on stage.

UPD: And another one thing. You CAN NOT hide some content under mask in terms of how ProLoader defines loaded content dimensions. Although your instances looks on stage in external SWF as you expected and Property Inspector also shows expecting height and width, ProLoader INCLUDES details hidden under masks while calculating loaded content size.

June 26, 2011

Was playing around a bit more, replaced Loader with ProLoader and it did the job!

Now I have access to instances in my external SWF by referencing via dot (ControlPanel.Power_BTN etc.)

However, ProLoader causes some difficulties with positioning ControlPanel on the stage, shifting it right for about 900 pixels...

Inspiring
June 26, 2011

If Power_BTN is an instance on timeline - it is not property but an instance on display list. Thus - it cannot be accessed via dot notation.

Try:

ControlPanel.getChildByName("Power_BTN");

Or:

Object(ControlPanel)["Power_BTN"];

June 26, 2011

Thanks for the reply Andrei1.

Unfortunately it doesn't work either...

ControlPanel.getChildByName("Power_BTN") returns null

Object(ControlPanel)["Power_BTN"] returns the same Error #1069...

Any other suggestions?