COCOSTUDIO--JS 3 Final Control events

Source: Internet
Author: User
Tags addchild event listener

Recently tried the next Cocos IDE, then the engine with the COCOS2DX JS 3 final, need to build runtime, the following are some of Cocos studio related events:

To add an event listener:

        button var root = Ccs.uiReader.widgetFromJsonFile ("Res/uibutton_editor/uibutton_editor_1.json");                This.addchild (root);        var Back_label = ccui.helper.seekWidgetByName (Root, "back");        Back_label.addtoucheventlistener (This.backevent,this);        var button = Ccui.helper.seekWidgetByName (Root, "button_123");        Button.addtoucheventlistener (This.touchevent,this);        var Title_button = ccui.helper.seekWidgetByName (Root, "button_126");        Title_button.addtoucheventlistener (This.touchevent,this);        var Scale9_button = ccui.helper.seekWidgetByName (Root, "button_129");                                Scale9_button.addtoucheventlistener (This.touchevent,this);        check box var root = Ccs.uiReader.widgetFromJsonFile ("Res/uicheckbox_editor/ui_checkbox_editor_1.json");        This.addchild (root);        var checkbox = Ccui.helper.seekWidgetByName (Root, "checkbox_540");        Cc.log (Checkbox.addeventlistener); CheckBox.AddEventListener (This.selectedstateevent,this); List view var listview_res = ["res/uilistview_editor/uilistview_vertical_editor/ui_l Istview_editor_1.json "," Res/uilistview_editor/uilistview_horizontal_editor/ui_listview_horizon        Tal_editor_1.json "];        var root = Ccs.uiReader.widgetFromJsonFile (Listview_res[0]);                This.addchild (root);        var ListView = ccui.helper.seekWidgetByName (Root, "listview_1214");                                Listview.addeventlistener (This.selecteditemevent,this);        Page view var root = Ccs.uiReader.widgetFromJsonFile ("Res/uipageview_editor/ui_pageview_editor_1.json");                This.addchild (root);        var pageView =ccui.helper.seekwidgetbyname (Root, "pageview_1269");                                Pageview.addeventlistener (this.pageviewevent, this); RichText var richtext = ccui.Richtext.create ();        Richtext.ignorecontentadaptwithsize (FALSE);        Richtext.setcontentsize (Cc.size (120, 100)); var Re1 = Ccui.        Richelementtext.create (1, Cc.color.WHITE, 255, "This color was white", "Helvetica", 10); var Re2 = Ccui.        Richelementtext.create (2, Cc.color.YELLOW, 255, "and this is YELLOW.", "Helvetica", 10); var Re3 = Ccui.        Richelementtext.create (3, Cc.color.BLUE, 255, "This one is BLUE", "Helvetica", 10); var Re4 = Ccui.        Richelementtext.create (4, Cc.color.GREEN, 255, "and GREEN", "Helvetica", 10); var Re5 = Ccui.               Richelementtext.create (5, Cc.color.RED, 255, "Last one is RED", "Helvetica", 10); var re6 = Ccui.        Richelementtext.create (7, Cc.color.ORANGE, 255, "Have fun!!", "Helvetica", 10);        Richtext.pushbackelement (Re1);        Richtext.insertelement (Re2, 1);        Richtext.pushbackelement (Re3);        Richtext.pushbackelement (Re4);        Richtext.pushbackelement (RE5);  Richtext.pushbackelement (RE6);      Richtext.setposition (CC.P (1280/2, 720/2));                                This.addchild (RichText);        slider var root = Ccs.uiReader.widgetFromJsonFile ("Res/uislider_editor/ui_slider_editor_1.json");        This.addchild (root);        var slider = ccui.helper.seekWidgetByName (Root, "slider_738");        Slider.addeventlistener (This.sliderevent,this);        var Scale9_slider = ccui.helper.seekWidgetByName (Root, "slider_740");                       Scale9_slider.addeventlistener (This.sliderevent,this);        Text field var root = Ccs.uiReader.widgetFromJsonFile ("Res/uitextfield_editor/ui_textfield_editor_1.json");                This.addchild (root);        var textfield_normal = ccui.helper.seekWidgetByName (Root, "textfield_1109");        Textfield_normal.addeventlistener (This.textfieldevent,this);        var textfield_max_character = ccui.helper.seekWidgetByName (Root, "textfield_1110"); Textfield_max_character.addeventlistener (This.textfieldeveNt,this);        var Textfield_password = ccui.helper.seekWidgetByName (Root, "textfield_1107"); Textfield_password.addeventlistener (This.textfieldevent,this);

Individual event callbacks:

Widget Touchevent:function (sender, type) {switch (type) {case Ccui.    Widget.TOUCH_BEGAN:cc.log ("TOUCH down");    Break Case Ccui.    Widget.TOUCH_MOVED:cc.log ("TOUCH Move");    Break Case Ccui.    Widget.TOUCH_ENDED:cc.log ("TOUCH up");    Break Case Ccui.    Widget.TOUCH_CANCELED:cc.log ("TOUCH Cancelled");    Break    Default:break; }},//check box Selectedstateevent:function (sender, type) {switch (type) {case Ccui.    CheckBox.EVENT_SELECTED:cc.log ("SELECTED");    Break Case Ccui.    CheckBox.EVENT_UNSELECTED:cc.log ("unselected");    Break    Default:break; }},//List view selecteditemevent:function (sender, type) {switch (type) {case Ccui.    ListView.EVENT_SELECTED_ITEM:var Listviewex = sender;    Cc.log ("Select Child index =" + Listviewex.getcurselectedindex ());    Break    Default:break; }},//Page view pageviewevent:function (sender, type) {switch (type) {case Ccui.    PageView.EVENT_TURNING:var PageView = sender;    Cc.log ("page =" + (Pageview.getcurpageindex () + 1));    Break    Default:break; }},//slider sliderevent:function (sender, type) {switch (type) {case Ccui.    Slider.EVENT_PERCENT_CHANGED:var slider = sender;    var percent = slider.getpercent ();    Cc.log ("Percent" + percent.tofixed (0));    Break    Default:break; }},//Text field textfieldevent:function (sender, type) {switch (type) {case Ccui. TextField.    EVENT_ATTACH_WITH_IME:cc.log ("ATTACH with IME");    Break Case Ccui. TextField.    EVENT_DETACH_WITH_IME:cc.log ("DETACH with IME");    Break Case Ccui. TextField.    EVENT_INSERT_TEXT:cc.log ("INSERT words");    Break Case Ccui. TextField.    EVENT_DELETE_BACKWARD:cc.log ("DELETE word");    Break    Default:break; }    }



COCOSTUDIO--JS 3 Final Control events

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.