Solved

How to Target a dynamically created MC

Posted on 2008-06-14
7
771 Views
Last Modified: 2011-10-19
thanks for reading, here is the situation.

*** Using AS3 ***

I am creating a new object on the stage via the library and I want to specify it's name via an argument passed to the function.

OUTSIDE of the function, I need to be able to interact with the created object from other sprites, not unusual. The problem I am having is trying to target the new mc, creating it is not the issue.

So I need a simple statement like

newMC.visible = false;

However for some reason I cannot seem to get the target path correct. I've tried eveythig i can think of to no avail.
the code below should be self explanatory.

If you are going to go through the effort to respond, please be sure to test it first.

Thank you!
var btnHome;
 
function makeHeaderBtn(btnNum, hitName, btnName, link, theMainLabel, altLable1, altLabel2):void {
 
	//var holderName:MovieClip = new MovieClip();		
	var btnHolder:MovieClip = new MovieClip();
	
	
	// ADD HEADER BUTTON Button_Main
	var btnName:Button_Main = new Button_Main(); 
	btnName.x = 50;
	btnName.y = 100;
	addChild(btnName);
	trace(btnName); // o/p is instance22 (some insance number)
}
 
 
makeHeaderBtn(0, hit_button_home, btnHome, "link", "HOME", "", "");
 
// The following throws these errors: Error #1010: A term is undefined and has no properties.
btnHome.visible = false; // does not work
this.btnHome.visible = false; // does not work
 
// not sure if the following works or not, because although the instance is NOT visible,
// I get this error: 1120: Access of undefined property instance48.
 
instance48.visible = false;

Open in new window

0
Comment
Question by:MartiniMon
[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
7 Comments
 
LVL 43

Expert Comment

by:Rob
ID: 21787964
Can you post the class for Button_Main as the name doesn't look to be defined
0
 
LVL 1

Author Comment

by:MartiniMon
ID: 21788791
Just create any mc, put it in the lib and link it "Button_Main"

HYG
0
 
LVL 1

Author Comment

by:MartiniMon
ID: 21788805
Here is a sample fla, I need tin find out why this line is not functioning. Perhaps they way I am declaring the instance name? I can't seem to get the targeting, it must be somethign very simpled I am overlooking.

Thanks!

Cheers!

PS dont know why EE doesn't allow you yoy upload flas.
test.fla.txt
0
Independent Software Vendors: 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!

 
LVL 10

Expert Comment

by:bluefezteam
ID: 21789271
can you not apply trace(this); in your function

and that should show you the path from a _level0 structure?
0
 
LVL 1

Author Comment

by:MartiniMon
ID: 21789309
No.

Ive tried that.


If I put a trace this in the lib mc I get:  this = [object Button_Main]
and this as noted above:
trace(btnName); // output is instance22 (some instance number)

Here perhaps is a better request for this question as I seem to be having problems in descripbing what I want to accomplish.

A. Create a Function that instantiates a linked object (ANY) from the library.
Function needs to create 3 instances with unique names.
names to be used are btnPie, btnCake and BtnBeer - not necessarily in that order :-)
Function goes in frame one of the main timeline


B. In frame two, write a statement that changes the color of instance 1, position of instance 2 and visibility of instance 3.

ie: btnBeer.x = 100; // etc

0
 
LVL 12

Accepted Solution

by:
SamuelRostol earned 500 total points
ID: 21789730
Hi there,

The problem is not the instance name, but the fact that you actually never assign the button to the variable "btnHome"..

Try to change your code to the following snippet;
var btnHome;
 
function makeHeaderBtn(btnNum, hitName, btnName, link, theMainLabel, altLable1, altLabel2):void {
 
	//var holderName:MovieClip = new MovieClip();		
	var btnHolder:MovieClip = new MovieClip();
	
	
	// ADD HEADER BUTTON Button_Main
	var btnName:Button_Main = new Button_Main(); 
	btnName.x = 50;
	btnName.y = 100;
	addChild(btnName);
	trace(btnName); // o/p is instance22 (some insance number)
 
	// Notice this line - it sets the button up so that you can
	// find it from outside the function.
	btnHome = btnName;
}
 
// Rest of code...

Open in new window

0

Featured Post

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
CorelDraw x7 requiring Adobe to print accurately?? 3 163
Extracting Icon but saves ico as blank 9 114
Flash Converter 8 144
Help with SimpleXML charts with PHP 4 112
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…
Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Learn how to create interesting presentations by including videos to keep your audience engaged using Prezi. Select "Insert" from the top menu in your Prezi editor: Select "YouTube Video": Paste the video URL into the prompt: "Select "Insert":…

752 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