Skip to main content
Participant
August 27, 2008
Question

Reaching an MC from a class

  • August 27, 2008
  • 2 replies
  • 390 views
Driving me crazy...

I wanna reach a Mc ALREADY MANUALLY ON STAGE (not addes with addChild) from a class. I can't.

the instance of the Mc on stage is 'McTestA'.

So, on my animation, I got :
var objet:ClasseTest;
objet = new ClasseTest(stage, McTestA);

as you see, I pass the 'stage' and the 'mc' as references to my class.
Here is the class :

package {
import flash.display.MovieClip;
import flash.display.Stage;
public class ClasseTest extends MovieClip {
public var refStage:Stage;
public var mc:MovieClip;
function ClasseTest(pRefStage:Stage, pMc:MovieClip) {
refStage=pRefStage;
mc=pMc;
refStage.mc.x=200;
}
}
}

AS error is : 'poperty undefined'.
CRAAAAZYYYYY !!!!!!
2 files here : http://tapiocadesign.com/AS3_question1.zip
This topic has been closed for replies.

2 replies

Inspiring
August 27, 2008
I don't see why you need the reference to the stage in ClasseTest. I think it is enough to just pass mc and set its parameters.

But if you insist to have the reference, try: refStage.getChildAt(getChildIndex(mc)).x=200;

My understanding is that stage is always the same thing for all the objects in the application - so you can reference it from anywhere - no need for custom referencing.
Inspiring
August 27, 2008
This is definitely not the only way to do this. As Im sure someone will elaborate on the Stage class. I have choosen to type the 'stage/maintimeline' as a MovieClip.