?
Solved

AS3 - how to refer to a dynamically added child swf

Posted on 2008-10-21
4
Medium Priority
?
1,189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
The goal of the tutorial is to teach the user how to select which audio input to use. Once you have an audio input plugged into the laptop or computer, you will go into the audio input settings and choose which audio input you want to use.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses

764 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