Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 1.0 (and below)

Reply
 
Thread Tools Rate Thread Display Modes
Old 05-18-2003, 01:44 AM   #1
EnSanity
Registered User
 
Join Date: Apr 2003
Posts: 37
Send a message via AIM to EnSanity
Default get instance name?

Is there some type of method that on (press) you could find out what the instance name is of the variable clicked?

example: there is a button which has an instance name of myButton

- now when i click it do something like

instancename = getVariableClicked();
and instancename would get the value myButton
i dont know if there is a method like this, is there?

Thanks!
EnSanity is offline   Reply With Quote
Old 05-18-2003, 02:01 AM   #2
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Howdy...

You can use _name to get the instance name, but you cannot reset/change the instance name via script...
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 05-18-2003, 03:36 AM   #3
EnSanity
Registered User
 
Join Date: Apr 2003
Posts: 37
Send a message via AIM to EnSanity
Default

:-D dont need to!
EnSanity is offline   Reply With Quote
Old 05-18-2003, 03:59 AM   #4
EnSanity
Registered User
 
Join Date: Apr 2003
Posts: 37
Send a message via AIM to EnSanity
Default

hrmmmm BLUE, how does this ._name function work? i've tried a couple different ways and havent gotten it to work. I have read in my flash book that
Quote:
but quite honestly, using the _name property to determine the name of a movie clip instance would be rather silly. After all, to examine or set an object's properties, you would already need to know the name of the object. And if you already know the name of an object, the _name property will have the value that you already know.
Well that would defeat the purpose of the property now wouldnt it? If it cant tell the name of the object being selected, then it cant help me. Can it in someway that im missing?

Example: say the button's instance name is button1 and

on release i want the variable instname to get the instance name of this button. So if everything worked instname would equal "button1" can you help me get this?
EnSanity is offline   Reply With Quote
Old 05-18-2003, 04:16 AM   #5
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Well... I am not quite sure what you are trying to do there...

Let's make it simple...

Create a button on the stage, and give it 'Btn_Test' as an instance name...
In frame 1 of the movie, add this script...
ActionScript Code:
Btn_Test.onPress = function () {     trace(this._name); }
Run the movie and click on it, and see the output panel...

Is it what you are looking for???
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 05-18-2003, 04:46 AM   #6
EnSanity
Registered User
 
Join Date: Apr 2003
Posts: 37
Send a message via AIM to EnSanity
Default

This is what i am trying to do: I am letting the user dynamically create buttons, so the only thing i know about the instance name is that there will be a w to start it a number proceeding it (ex. w12) so at some point during my script i want the user to be able to add text associated to each button. So basically i need to be able to get the instance name to modify the text associated with it. Do you follow? Since i am duplicating these "buttons" from a main movie clip i could add a generic script to that button saying like
Code:
on(release){
    instname = this._name;
}
would that work?

Regards,
EnSanity
EnSanity is offline   Reply With Quote
Old 05-18-2003, 04:57 AM   #7
EnSanity
Registered User
 
Join Date: Apr 2003
Posts: 37
Send a message via AIM to EnSanity
Default

hrmm no that would be too easy. wow - that is the most pointless function EVER! to make that work i would have to go

trace(yay._name);

which wold give me the output "yay"....... how stupid. Do you have any idea how i could accomplish what i stated i needed to do in the previous post? Im stuck! - EnSanity
EnSanity is offline   Reply With Quote
Old 05-18-2003, 08:38 AM   #8
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Hm... Obviously I am not getting what you are saying...

So, you have buttons on the stage via duplicateMovieClip() function... And, you want to know the instance name of the selected/pressed movieclip, and save it to the variable???

Your script should do what I've just said...
ActionScript Code:
on (release){     instname = this._name; }
I don't understand what you meant by 'too easy'... Do me a favor and post your code or sample file...
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue is offline   Reply With Quote
Old 05-18-2003, 07:57 PM   #9
EnSanity
Registered User
 
Join Date: Apr 2003
Posts: 37
Send a message via AIM to EnSanity
Default

well blue, i have found out how to make it work.

on the one being duplicated i added this code:
Code:
_root.instFunction(this);
and on the root timeline i added

Code:
function instFunction (obj){
	_root.instname=obj._name;
	trace (instname);
}
aparently my book The Complete Reference: Macromedia Flash MX was wrong. In it was that quote i posted a few posts ago about _name property being worthless. I have since then written them a letter and figured out my problem. But i do have a question i can ask of you. Right now i have a delete button and on it is the code
Code:
on (release)
{
	removeMovieClip(_root.instname);
}
Now for some reason this does not work. instname gets the value once a copied button is clicked. How should i fix this?
EnSanity is offline   Reply With Quote
Old 05-18-2003, 09:14 PM   #10
CyanBlue
Super Moderator
 
CyanBlue's Avatar
 
Join Date: Jan 2002
Location: Centreville, VA
Posts: 26,666
Default

Glad you got it working...

removeMovieClip() function will only delte instances of the movieclip that has been laid on the stage via attachMovie() function or duplicateMovieclip() function... Make sure of that... and also make sure that _root.instname is within the scope... and try this code...
ActionScript Code:
on (release) {     trace("_root.instname = " + _root.instname);     _root.instname.removeMovieClip();     // or     _root[instname].removeMovieClip(); }
Let me know...
__________________
CyanBlue / Jason Je / Macromedia Certified Flash Developer & Designer
http://CyanBlue.FlashVacuum.com
http://www.FlashVacuum.com
http://tutorials.FlashVacuum.com

Do NOT PM, Email or Call me... Your question belongs right in this forum...
CyanBlue 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 11:57 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.