as3 as java

Java code posted by awong
created at 05 Dec 21:13, updated at 06 Dec 20:52

Edit | Back
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package ui
{
  import flash.display.DisplayObjectContainer;//你好
  import flash.events.Event;
  import ui.events.ButtonEvent;
  import ui.events.GenericPopupEvent;

  public class GenericPopup extends PopupDialog // PopupDialog is a class defined in a SWC file
  {
    // When the user calls "show" or "hide", this is the container this popup is added/removed to/from
    private var popupContainer:DisplayObjectContainer;

    public function GenericPopup( popupContainer:DisplayObjectContainer )
    {
      super();
      this.popupContainer = popupContainer;

      Button.makeIntoButton(leftButton);
      Button.makeIntoButton(rightButton);

      // "leftButton" and "rightButton" are the instance names of children found in the artwork
      leftButton.addEventListener(ButtonEvent.SELECTED, onLeftButtonSelected);
      rightButton.addEventListener(ButtonEvent.SELECTED, onRightButtonSelected);
    }

    protected function onRightButtonSelected(event:Event):void
    {
      dispatchEvent( new GenericPopupEvent( GenericPopupEvent.OPTION_SELECTED, rightButton.label.text ) );
    }

    protected function onLeftButtonSelected(event:Event):void
    {
      dispatchEvent( new GenericPopupEvent( GenericPopupEvent.OPTION_SELECTED, leftButton.label.text ) );
    }

    public function show( displayText:String, option1:String, option2:String ):void{
      popupContainer.addChild( this );

      // "message" is the instance name of a text-field found in the artwork
      message.text = displayText;

      // "leftButton" and "rightButton" are instances of the "ButtonArtwork" class
      // the "ButtonArtwork" class has a text-field with instance name: "label"
      leftButton.label.text = option1;
      rightButton.label.text = option2;
    }

    public function hide():void{
      popupContainer.removeChild(this);
    }
  }
}
1.76 KB in 26 ms with coderay