Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 05-29-2012, 08:34 PM   #1
thumb
Registered User
 
Join Date: May 2012
Posts: 6
Default Passing MC name in as a function variable?

I'm having some troubles trying to create a function that uses a movieclip reference as one of the function parameters - I suppose I'm not sure how to properly call it so it carries out things on the proper MC?

While the actual function has a fair bit more to it than below, it basically looks like....

Code:
function clickedit(x, y) {

	if (_root.tileshuffled[x] == "a") {
		y.gotoAndStop("a");	

	}

}
...where x is a number referencing an array entry, and y is a movie clip reference.

It's called like:

Code:
on(press) {
	_root.clickedit(0, "t1");
}

The parameter x works fine, passing in the number to the function and working how I'd expect.

The parameter y doesn't seem to work as-is; it doesn't do anything when I try and use 'y' instead of hard coding the MC name into the function, though it works fine when hard coded like below:

Code:
function clickedit(x, y) {

	if (_root.tileshuffled[x] == "a") {
		t1.gotoAndStop("a");	
	}

}
Any tips on what I'm doing wrong here? I'm just trying to pass in the MC name "t1" to the function so it treats it accordingly.

Thanks!
thumb is offline   Reply With Quote
Old 05-29-2012, 09:49 PM   #2
arkitx
Senior Member
 
Join Date: Jan 2011
Posts: 703
Default

Welcome thumb

ActionScript Code:
function clickedit(x, y) {     if (_root.tileshuffled[x] == "a") {         this[y].gotoAndStop("a");     } }

OR

ActionScript Code:
function clickedit(x, y) {     if (_root.tileshuffled[x] == "a") {         _root[y].gotoAndStop("a");     } }



__________________
Regards

arkitx
arkitx is offline   Reply With Quote
Old 05-29-2012, 10:03 PM   #3
thumb
Registered User
 
Join Date: May 2012
Posts: 6
Default

Thank you kindly! That did the trick.
thumb is offline   Reply With Quote
Old 05-29-2012, 11:20 PM   #4
Prid
Prid - Outing
 
Prid's Avatar
 
Join Date: Oct 2009
Location: Halden, Norway
Posts: 1,191
Send a message via MSN to Prid Send a message via Skype™ to Prid
Default

EDIT: oops, had this tab open for a while

-----------------

Hi,

you're only passing a String to your function, and have no code in your function to convert the String to a defined MovieClip, which basically means that you're telling a String to gotoAndStop("a")

Either pass the y argument as a MovieClip by simply typing t1 without quotes - this will pass the full path to the MovieClip to your function:

ActionScript Code:
on(press) {     _root.clickedit(0, t1); }

If you want to pass a String, then you'll have to make Flash look for the MovieClip with the same instance name. This can be achieved by using, scope[stuff_to_look_for], where scope is for example _root, _parent, this, etc. and the inside of the bracket is whatever you want (adding Strings, variables and Numbers together to make up a name), but whatever you type in there, Flash will look for an Object with the same name. In this case, when you send "t1" as a String into your Function, it will look for an Object with the same instance name, which is the movieclip with the instance name, t1, and refer to it. Here:

ActionScript Code:
function clickedit(x, y) {     if (_root.tileshuffled[x] == "a") {         this[y].gotoAndStop("a");        } }

Hope this helps
__________________
I have returned, and am now 18
Prid is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:11 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.