AS3 Stepping Device

Source: Internet
Author: User
Tags addchild

When writing stepping, the general requirements of TextField can also support input, and is greater than or equal to 0 of meaningful numbers, such as "01" is not possible. Here you need to introduce a little knowledge (in the spirit of not knowing, knowing the purpose of understanding)

Event:

Textevent.text_input

Event.change

First, textevent.text_input: There is text to be entered, and is an input of one (to be explained later)

Event.change : triggered after text input

For: TextField, there is a read-only property: Careindex, meaning: The index of the position of the cursor insertion point

Well, the previous stepper was implemented:

 package com.niuniu.module.room.view.item{ import com.game.common.config; import  com.game.common.GameUtil; import com.game.common.StageInfo; import  com.game.modulebase.view.baseview; import com.game.modulecall.modulecallmanger; import  com.game.ui.layer.layermanager; import com.game.ui.layer.layertype; import  com.game.ui.reslib.reslib; import com.niuniu.gameeventtypestr; import  com.niuniu.common.usermanager;  import flash.display.simplebutton; import  flash.display.sprite; import flash.events.event; import flash.events.mouseevent;  import flash.events.textevent; import flash.text.textfield; import  flash.text.textfieldtype;  import tw.ui.alertdialog; /**  *  into Chips panel   *  @author  kayer  * */ public final class buychipspanel extends baseview {  private var  $btnClose  : SimpleButton;   private var  $btnMinus  : simplebutton;  private var $ btnplus : simplebutton;  private var  $btnSure  : SimpleButton;   private var  $labValue  : textfield;    private var $ bgmask:sprite;//background Matte   private var  $isMask: Boolean;    private var   $STEPOFF  : uint = 1;  /** The maximum number of chips to buy this time */  private var $ maxbuyingchips : uint = 0;  /** text */  private var  $text   : string;  /**   *  @param   $isMask  :  modal    *   @param   $STEPOFF  :  Stepper Step Size    * */  public function  Buychipspanel (  $isMask &Nbsp;: boolean = true ,  $stepOff  : uint = 1 )   {    this. $isMask  =  $isMask,    this $stepOff  =  $stepOff;    this. $maxBuyingChips  = config.maxchipsbuywhthmobean (  usermanager.instance.myselfmobean );    super ();  }  override  Protected function initdis (): Void  {   if ( this. $isMask  )     {    this. $bgMask  = new sprite ();     LayerManager.instance.getLayer (Layertype.layer_popup_dialog). AddChild (this. $bgMask);   }    this._mc = reslib.getmovieclip (' com.niuniu.module.room.BuyChips ');// Com.niuniu.module.room.room_view   this.addchild ( this.mc );    this.$ btnclose = this.mc["Btnclose"];   this. $btnMinus  = this.mc["Btnminus"];   this. $btnPlus  = this.mc["Btnplus"];    this. $btnSure  = this.mc["Btnsure"];//btnsure   this. $labValue  = this.mc[" Labvalue "];   this. $labValue. type = textfieldtype.input;//   this.$ Labvalue.mouseenabled = false;   this. $labValue .text =  "0";    super.makeenabled ( true );  }  override public function  Onstageresizelistener (e:event): Void  {   if ( this. $isMask  )     {    if  ( this. $bgMask  != null )  {      this. $bgMask. Graphics.clear ()      this. $bgMask. Graphics.beginfill (  0x000000 , 0.2 )      this. $bgMask. Graphics.drawrect (0,0, Stageinfo.stage.stagewidth,stageinfo.stagE.stageheight);      this. $bgMask. Graphics.endfill ();    }    }   this.setxy (  (stageinfo.width - this.width )  >>1  ,  ( StageInfo.HEIGHT - this.height )  >>1 );  }   override protected function initevent (): void  {   this.$ Btnclose.addeventlistener ( MouseEvent.CLICK , onClickHandler );    this.$ Btnminus.addeventlistener ( MouseEvent.CLICK , onClickHandler );    this.$ Btnplus.addeventlistener ( MouseEvent.CLICK , onClickHandler );    this.$ Btnsure.addeventlistener ( MouseEvent.CLICK , onClickHandler );    this.$ Labvalue.addeventlistener ( TextEvent.TEXT_INPUT , onChipsNumChange );    this. $labValue. AddEventListener ( eVent. change , onchipsnumchangea );    stageinfo.stage.addeventlistener (Event.RESIZE,  onstageresizelistener);   }  override protected function removeevent () : Void  {   this. $btnClose. RemoveEventListener ( MouseEvent.CLICK ,  onclickhandler )    this. $btnMinus. RemoveEventListener ( MouseEvent.CLICK ,  onclickhandler )    this. $btnPlus. RemoveEventListener ( MouseEvent.CLICK ,  onclickhandler )    this. $btnSure. RemoveEventListener ( MouseEvent.CLICK ,  onclickhandler );    this. $labValue. RemoveEventListener ( textevent.text_input ,  onChipsNumChange     this. $labValue. RemoveEventListener ( event.change ,  onChipsNumChangeA );    stageinfo.stage.addeventlistener (event.resize,  Onstageresizelistener); &nbSp; }  private function onclickhandler (  $e  : MouseEvent )  :  void  {   switch (  $e .target.name )    {     case  "Btnclose":      this.destroy ();      break;    case  "Btnminus":      trace ("BtnMinus");      this.stephandlder ( - this. $STEPOFF  );      break;    case  "Btnplus":      trace ("BtnPlus");      this.stephandlder ( this. $STEPOFF  );     break;     case  "Btnsure":      trace ("Btnsure");      this.onsure ();      break;   }  }  private  function onchipsnumchange(  $e  : TextEvent )  : void  {   if (  this.$ LABVALUE.TEXT.SUBSTR (0,1)  ==  "0"  &&  ($e. Currenttarget as textfield). caretindex > 0 )    {    this. $text  = this.$ Labvalue.text;   }   else   {    if (  IsNaN ( number ($e. Text)   )  )      this. $text  = this.$ Labvalue.text;    else if ( int (  $e .text )  == 0 )       {     if (  ($e. Currenttarget as textfield). caretindex == 0 )       this. $text  = this. $labValue. Text ;      else      this. $text  =  "";     }   &nbSp;else     this. $text  =  "";   }  }   Private function onchipsnumchangea (  $e  : Event )  : void  {    if ( this. $text  !=  ""  )     this. $labValue. text =  this. $text;   else   {    var buffer :  Number = number ( this. $labValue .text );     if ( buffer >  this. $maxBuyingChips  )      this. $labValue. text = this.$ Maxbuyingchips.tostring ();   }  }  /**   *  display     * */  public function show ()  : void  {    onstageresizelistener (null);    layermanager.instance.getlayer (LayerType.LAYER_POPUP_ DIALOG). AddChild (this); &NBSP;&NBSP;}&Nbsp; /**   *  Handling Redemption    * */  private function  Onsure ()  : void  {   if ( uint ( gameutil.trim (this. $labValue. Text  )  )  <= 0 )    {    alertdialog.createwarnwin (   " , " Please reset the redemption amount! ",  0 , alertdialog.viewok , function (  $e  :   String );   }   : void{  } , true )   else   {    modulecallmanger.dise ( GameEventTypeStr.NOTYFY _magicbean_2_chips_req , uint ( gameutil.trim (this. $labValue .text )  )  );     this.destroy ();   }  }  /**   *  Implementing the Stepper Algorithm    *  @param   $off  :  (+-  stepping Step)    * */   private function&nBsp;stephandlder (  $off  : int )  : void  {   var  Buffer : number = number ( this. $labValue .text )  +  $off;    if ( buffer >= 0 )    {    if ( buffer  <= this. $maxBuyingChips  )      this. $labValue .text =  Buffer.tostring ();     else    {     this.$ Labvalue.text == this. $maxBuyingChips. toString ();    }   }   }  override protected function removedis ():void  {    if ( this. $isMask  )    {    if ( this. $bgMask  != null  )     {     layermanager.instance.getlayer (LayerType.LAYER_ Popup_dialog). RemoveChild (this.$Bgmask);      this. $bgMask  = null;    }    }  }  override public function destroy ():void  {    super.destroy ();   } }}

Now you need to explain: Textevent.text_input , one of the input "Woshi" when

650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/84/79/wKiom1eRnibhD3oPAADU0h8KIXg522.png-wh_500x0-wm_3 -wmp_4-s_3856694123.png "title=" X1.png "alt=" Wkiom1ernibhd3opaadu0h8kixg522.png-wh_50 "/>

First get: "W", Get "O" for the second time, because textevent.text_input: There is text to be entered (the value of target (TextField) does not change, the cursor does not change), so, Careindex has been 1 (at the default value "0" Input later)


650) this.width=650; "Src=" Http://s5.51cto.com/wyfs02/M02/84/79/wKioL1eRnkvhM4kaAAC_WYA2-1E672.png-wh_500x0-wm_3 -wmp_4-s_3010703698.png "style=" Float:none; "title=" "W" "alt=" Wkiol1ernkvhm4kaaac_wya2-1e672.png-wh_50 "/>

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/84/79/wKiom1eRnkyRWJi8AACt7_vSyEU387.png-wh_500x0-wm_3 -wmp_4-s_2557910954.png "style=" Float:none; "title=" "O" "alt=" Wkiom1ernkyrwji8aact7_vsyeu387.png-wh_50 "/>


This article from "Better_power_wisdom" blog, reproduced please contact the author!

AS3 Stepping Device

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.