-
LukewarmSteak - Jordan Embury
[RESOLVED] referring to an instance with a variable??
i can't really explain what I'm trying to do here... but here it goes
i'm trying to access an instance by using a variable but when i try to manipulate a property to the instance (by referring to it with a variable) it only recognizes it as a string... for instance... (pun intended??)
public var prevbutton:String = "btn1";
trace(["page"+prevbutton]);
// which traces - pagebtn1
trace(pagebtn1);
// which traces the instance class - [object btn1pageclass]
I want to call the instance by using a variable... how do i do this?
-
lemon juice hurts your eyes
Try this:
PHP Code:
public var prevBtn:btn1pageclass = pagebtn1;
So you make a variable with the same type as your pagebtn1 (I assumed it was btn1pageclass, but if it's any different, change the name after the colon) and set it equal to the object you want to access.
Now you should be able to do prevBtn.x & prevBtn.y (if the object inherits of a DisplayObject) and functions inside of the class
Florian Vanthuyne
WAR AGAINST SOLVED THREADS
mark yours as Resolved under Thread Tools!
-
LukewarmSteak - Jordan Embury
this defeats the purpose - my variable changes from btn1 thru btn6 and i need to say
lets just say...// if ["page"+variable] = pagebtn1... then i want something like this...
this["page"+variable]gotoAndPlay(1);
how do i do this??
-
LukewarmSteak - Jordan Embury
... or... now that i can get the string to say pagebtn? (?=1-6), how do i convert the string into an instance definition?
-
WohOoooooo
not sure what your trying to do but you have the getChildByName() function
if you have 5 movieclips named mc1, mc2 ... then your could use
var mcNum:int = 1;
getChildByName('mc' + mcNum);
what do you get if you do trace(getChildByName("page"+prevbutton));?
-
LukewarmSteak - Jordan Embury
trace("getchild "+getChildByName("page"+prevbutton));
= getchild null
=(__
-
WohOoooooo
You cant use the name of the class, here is a example of how u use the getChildByName()
var s:Sprite = new Sprite();
s.name = "btn1";
addChild(s);
// and then
var btnNum:int = 1;
getChildByName("btn" + btnNum)
-
LukewarmSteak - Jordan Embury
that sounds reasonable thanks i'll try right now
-
LukewarmSteak - Jordan Embury
thanks... i think it worked right away...
public var pagebtn1:btn1pageclass = new btn1pageclass();
pagebtn1.name = "pagebtn1";
addChild(pagebtn1);
trace(this.getChildByName("page"+prevbutton));
////// traces --- [object btn1pageclass]
thank you so much ZOMPO - SOLVED
-
LukewarmSteak - Jordan Embury
so can i not now say...
PHP Code:
getChildByName(page+prevbutton).gotoAndPlay(1);
?????
i get error:
1061: Call to a possibly undefined method gotoAndPlay through a reference with static type flash.displayisplayObject.
-
WohOoooooo
you could try
var mc:MovieClip = getChildByName(page+prevbutton) as MovieClip;
mc.gotoAndPlay(1);
-
LukewarmSteak - Jordan Embury
holy F... you're amazing... great thinking... ZOMPO +=1
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|