How can I make this code by oop

Tag: flash , actionscript-3 , oop Author: myuehuai Date: 2010-08-29

I've a button called profile_btn

I want to make this code by OOP .

profile_btn.addEventListener(MouseEvent.CLICK,profile_btnClickHandler);
function profile_btnClickHandler(ev:MouseEvent):void
{
    //The actual code to jump to a specific frame
    this.gotoAndPlay('play');
}

Also, how can I include three classes to a specific frame by actionscript3 that aren't related to any object

Line 7 1046: Type was not found or was not a compile-time constant: profile_btn.
profile_btn should be an instance name of a button on stage.....for the error u just mentioned.
The instance name 'profile_btn' is declared on an object of type profile_btn but there is a conflicting use of the instance name 'profile_btn ' on an object of type flash.display.SimpleButton.
it's a name of btn in the library and the class linked to this button i just want to create the button dynamically and go to the frame i want
"adding 3 classes to a frame" doesn't make sense.Also, I think it would be better if you ask new questions in new threads rather than editing the old ones.

Best Answer

The following can be used if you have a class (the name you specified in linkage) profile_btn.

var myButton:profile_btn =new profile_btn()

If your want to add it to stage use:

stage.addChild(myButton);

So you code might look as

var myButton:profile_btn =new profile_btn()

stage.addChild(myButton);

myButton.addEventListener(MouseEvent.CLICK,profile_btnClickHandler);

function profile_btnClickHandler(ev:MouseEvent):void
{
    //The actual code to jump to a specific frame
    this.gotoAndPlay('play');
}

comments:

i get this error Error: Error #1023: Stack overflow occurred. at flash.display::MovieClip/get currentScene() at fl.motion::AnimatorBase/handleEnterFrame() at btn_profile()
and how to include this class in a specific frame by actionscript3
I don't get it, all you have to do is set the button's "class" value to profile_btn. Rest the code will automatically reference & add it. Ohh make sure you check "export in frame 1" & "export in AS".
I copy this code without editing and it's work without errors but the btn doesn't appear ,
and if i want to make it appear in a specific frame how can i make it , note the button in the library i didn't put it in the stage as i use addChild method