class Main extends Egret. Displayobjectcontainer {/** * Portal file, first execution of the construction method * This instantiates a stage as large as the screen of a mobile phone*/Public Constructor () {super (); This. Once (Egret. Event.added_to_stage, This. Begin, This ); } /** * The method that executes after the import file is loaded successfully * is also the beginning of the logic, moving the display object by Touch*/private Begin (Event:egret. Event) {/** * Create a text box, set a scrollRect limit display range * Text: text content * ScrollRect: Display range * Cacheasbitmap: whether Cache Display Objects*/ varBigtext:egret. TextField =NewEgret. TextField (); Bigtext.text= "Pan and scroll display objects, pan and scroll display objects"; Bigtext.scrollrect=NewEgret. Rectangle (0, 0, 640, 50); Bigtext.cacheasbitmap=true; Bigtext.x= 0; Bigtext.y= 10; This. AddChild (BigText); /** * Create a left shift, a right move button * Ev.currenttarget gets the name of the object that triggered the event*/ varBtnleft:egret. Shape =NewEgret. Shape (); BtnLeft.graphics.beginFill (0xcccc01); BtnLeft.graphics.drawRect (0, 0, 50, 50); BtnLeft.graphics.endFill (); Btnleft.x= 50; Btnleft.y= 100; This. AddChild (Btnleft); Btnleft.touchenabled=true; Btnleft.addeventlistener (Egret. Touchevent.touch_tap, Onscroll, This); varBtnright:egret. Shape =NewEgret. Shape (); BtnRight.graphics.beginFill (0x01cccc); BtnRight.graphics.drawRect (0,0,50,50); BtnRight.graphics.endFill (); Btnright.x= 150; Btnright.y= 100; This. AddChild (Btnright); Btnright.touchenabled=true; Btnright.addeventlistener (Egret. Touchevent.touch_tap, Onscroll, This); functionOnscroll (Ev:egret. TouchEvent):void { varRect:egret. Rectangle =Bigtext.scrollrect; Switch(ev.currenttarget) { CaseBtnleft:rect.x+ = 20; Break; CaseBtnright:rect.x-= 20; Break; } bigtext.scrollrect=rect; } }}
5. Move text around