public Button(DisplayObject upState, string text ="", DisplayObject downState=null, TextFormat format=null) { //if (upState == null) throw new ErrorEvent("Texture cannot be null"); mParent = upState.parent; mUpState = upState; mDownState = downState != null ? downState : upState; mBackground = upState; mTextFormat = format; mScaleWhenDown = 0.9f; mAlphaWhenDisabled = 0.5f; mEnabled = true; mIsDown = false; mUseHandCursor = true; mTextBounds = new Rectangle(0, 0, upState.width, upState.height); mContents = new Sprite(); mContents.addChild(mBackground); addChild(mContents); //addEventListener(TouchEvent.TOUCH, onTouch); addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); if (text.Length > 0) this.text = text; this.x = upState.x; this.y = upState.y; upState.x = upState.y = 0; if(mParent != null) (mParent as MovieClip).addChild(this); }