Solved

AS3 - how to refer to a dynamically added child swf

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Array is not working ( AS2 ) 4 146
Flash player plugin 13 7 324
Download Adobe Flash Player 6 59
Shouldn't i be able to use an old win xp machine as an internet radio? 7 120
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

920 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now