Skip to main content
Participating Frequently
June 8, 2009
Answered

How to access MC instance when we have only its name as a String.

  • June 8, 2009
  • 2 replies
  • 714 views

Hello,

I am not good at  AS, but I am trying out.

I am sending the instance name (i.e. String)  of the MovieClip to  a function.

From that function I need to access that same instance of MovieClip using that name.

I have a MovieClip  Instance name     Planet_mc. And I am sending it to function abc()

abc(Planet_mc.name);

function abc(s:String):void

{

// do something to change the alpha of that instance.

}

Thanks

This topic has been closed for replies.
Correct answer kglad

sure you can:

abc(Planet_mc.name);


function abc(s:String):void

{
var Dragged:DisplayObject=getChildByName("Planet_mc");
Dragged.alpha = .5;

}

although it's even easier to use:

abc(Planet_mc);


function abc(s:DisplayObject):void

{
s.alpha = .5;

}

2 replies

kglad
Community Expert
Community Expert
June 8, 2009

you changed your message:


var Dragged:DisplayObject=getChildByName("Planet_mc");

Participating Frequently
June 8, 2009

Ya I changed bcoz thought it was not necessary.

with   var Dragged:DisplayObject=getChildByName("Planet_mc");

I cant do Dragged.alpha=0.1;

can I?

Plz tell me.

Thanks Venkat.

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
June 8, 2009

sure you can:

abc(Planet_mc.name);


function abc(s:String):void

{
var Dragged:DisplayObject=getChildByName("Planet_mc");
Dragged.alpha = .5;

}

although it's even easier to use:

abc(Planet_mc);


function abc(s:DisplayObject):void

{
s.alpha = .5;

}

kglad
Community Expert
Community Expert
June 8, 2009

your code looks good as long as you're within the scope of the movieclip's parent.