# Adding stage on the class

**URL:** https://forum.kirupa.com/t/adding-stage-on-the-class/320378
**Category:** Uncategorized
**Created:** [March 22, 2011, 7:06am UTC](https://forum.kirupa.com/t/adding-stage-on-the-class/320378 "2011-03-22T07:06:10Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![taint](https://avatars.discourse-cdn.com/v4/letter/t/b5a626/32.png) [@taint](https://forum.kirupa.com/u/taint)
#### Post date: [March 22, 2011, 7:06am UTC](https://forum.kirupa.com/t/adding-stage-on-the-class/320378/1 "2011-03-22T07:06:10Z")

</div>

i’ve been getting difficulties regarding how to put a stage on a .AS  
how should i declare it? I want to put my movie clip on the stage using a class only. i want my hero to go at the middle of the screen but it doesnt come out.

here’s my current code

```auto

package {
    
    import flash.display.Stage;
    import flash.display.MovieClip;
    import flash.events.Event;

    public class hero_class extends MovieClip {
        
        public function hero_class() {
            init();
        }
        private function init(){
            addEventListener(Event.ADDED_TO_STAGE, onStage);
        }
        
        private function onStage(e:Event){
            addEventListener(Event.ENTER_FRAME, onEnter);
        }
        
        private function onEnter(e:Event){
            this.x = stage.stageWidth/2;
            this.y = stage.stageHeight/2;
            addChild(this);
        }

    }
    
}

```
