Solved

AS3 - how to refer to a dynamically added child swf

Posted on 2008-10-21
4
1,186 Views
Last Modified: 2013-11-11
This has got to be so easy but I can't figure it out. In AS2, if you wanted to add a child swf to a parent, you'd create an empty movieclip and then load the swf into the movieclip. Then if you wanted to refer to the swf, you'd refer to the movieclip. For example,

this.childMovie._x = 20;

OK, so I'm working on an AS3 project now and I've loaded a child swf with the loader and I'm displaying it with addChild. Everything's great, except now I want to add some children to the child swf and I don't know what to call it! Is it's name the loader name? Is it stored there, sorta so that to refer to it, I'd say

swfLoader.addChild(newObj)

I'm just not sure and I'm getting some errors so I don't know if that means that I'm doing it wrong or if I just have an error somewhere else that I need to fix.
0
Comment
Question by:katyjack
  • 2
  • 2
4 Comments
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 22773266
to refer the movieClip, use "Loader.content"


for example, if you Loader instance name is "myLoader" then following will refer the child SWF

myLoader.content
0
 

Author Comment

by:katyjack
ID: 22775229
For example?

swfLoader.content.addChild(optionBtn);

When I do that, I get the error "Call to possibly undefined method addChild"
0
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 500 total points
ID: 22776276
You have to wait for loading completion before accessing loading SWF...

here is the sample code for your clarification:


		var swfLoader:Loader = new Loader();
		swfLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
		var _request:URLRequest = new URLRequest("external.swf");
		swfLoader.load(_request);
		addChild(swfLoader);
		
		
		function onComplete(ev:Event):void {
			var loader:LoaderInfo = LoaderInfo(ev.target);
			var mc = loader.content;
			// you may access external loaded SWF here..
			mc.addChild(optionBtn);
		}

Open in new window

0
 

Author Closing Comment

by:katyjack
ID: 31508600
You're exactly right - I had an onComplete function but I had the code to call the swf in another file and it was firing before the swf was loaded. Thanks for your help.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Script to Delete registry entry based on Product name 6 169
Adobe Flash player - Microsoft Edge 9 177
Play RTMP without Flash 3 650
HTML 5 video and audio or Flash 1 61
I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question