Solved

AS3 - how to refer to a dynamically added child swf

Posted on 2008-10-21
4
1,187 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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Software Restriction Policy 8 893
How to emebed .XML into  flash to make a self contained .SWF 1 193
Open Source MP4 Flash Player 2 203
CD Rom not playing 13 87
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…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

739 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