• CookBook学习笔记


    1、更改swf设置:

    package{

    [SWF(width="",height="",backgroundColor="",frameRate="")]

    }

    2、Enterframe事件:addEventListener(EVENT.ENTER_FRAME,onenterframe);

    3、键盘事件:stage.focus = this;//焦点

    keyboardEvent.key_down//event.charcode

    4、new timerTest:Timer = New Timer(delay,repeatNum);//timerTest.add...(Timer.event,);//timerTest.start;//getTimer

    5、关于try catch(e:ERROR)//e.message容易出错的地方,try的话就不会报错了,游戏还可以玩

    6、静态属性static:不需要实例//常量const:不能改变

    7、检测操作系统:flash.system.capabilities.os//直接capabilities

    8、textfield:border边框  bordercolor边框颜色 background背景色 retrict限制字符 maxchar最大数量 condensewhite压缩空格

    9、嵌入字体:textfield可以嵌入字体

    10、获取焦点:stage.focus = sprite或者null

    11、设置选取文本或者光标:setSelection

    12、阻止输入:preventDefault

    13、sprite颜色colortransform

    14、发送XML:

    package{
    importflash.display.*;
    importflash.text.*;
    importflash.filters.*;
    importflash.events.*;
    importflash.net.*;
    publicclassXMLSendLoadExampleextendsSprite{
    privatevar_message:TextField;
    privatevar_username:TextField;
    privatevar_save:SimpleButton;
    publicfunctionXMLSendLoadExample( ){
    initializeDispaly( );
    }
    privatefunctioninitializeDispaly( ):void{
    _message=newTextField( );
    _message.autoSize=TextFieldAutoSize.LEFT;
    _message.x=10;
    _message.y=10;
    _message.text="Enterausername";
    _username=newTextField( );
    _username.width=100;
    _username.height=18;
    _username.x=10;
    _username.y=30;
    _username.type=TextFieldType.INPUT;
    _username.border=true;
    _username.background=true;
    _save=newSimpleButton( );
    _save.upState=createSaveButtonState(0xFFCC33);
    _save.overState=createSaveButtonState(0xFFFFFF);
    _save.downState=createSaveButtonState(0xCCCCCC);
    _save.hitTestState=save.upState;
    _save.x=10;
    _save.y=50;
    //Whenthesavebuttonisclicked,callthehandleSavemethod
    _save.addEventListener(MouseEvent.CLICK,handleSave);
    addChild(_message);
    addChild(_username);
    addChild(_save);
    }
    //Createsabuttonstatewithaspecificbackgroundcolor
    privatefunctioncreateSaveButtonState(color:uint):Sprite{
    varstate:Sprite=newSprite( );
    varlabel:TextField=newTextField( );
    label.text="Save";
    label.x=2;
    label.height=18;
    label.width=30;
    varbackground:Shape=newShape( );
    background.graphics.beginFill(color);
    background.graphics.lineStyle(1,0x000000);
    background.graphics.drawRoundRect(0,0,32,18,9);
    background.filters=[newDropShadowFilter(1)];
    state.addChild(background);
    state.addChild(label);
    returnstate;
    }
    privatefunctionhandleSave(event:MouseEvent):void{
    //Generatearandomscoretosavewiththeusername
    varscore:int=Math.floor(Math.random( )*10);
    //CreateanewXMLinstancecontainingthedatatobesaved
    vardataToSave:XML=<gamescore>
    <username>{username.text}</username>
    <score>{score}</score>
    </gamescore>;
    //PointtherequesttothescriptthatwillhandletheXML
    varrequest:URLRequest=newURLRequest("/gamescores.cfm");
    //SetthedatapropertytothedataToSaveXMLinstancetosendtheXML
    //datatotheserver
    request.data=dataToSave;
    //SetthecontentTypetosignalXMLdatabeingsent
    request.contentType="text/xml";
    //Usethepostmethodtosendthedata
    request.method=URLRequestMethod.POST;
    //CreateaURLLoadertohandlesendingandloadingoftheXMLdata
    varloader:URLLoader=newURLLoader( );
    //Whentheserverresponseisfinisheddownloading,invokehandleResponse
    loader.addEventListener(Event.COMPLETE,handleResponse);
    //Finally,sendofftheXMLdatatotheURL
    loader.load(request);
    }
    privatefunctionhandleResponse(event:Event):void{
    try{
    //Attempttoconverttheserver'sresponseintoXML
    varsuccess:XML=newXML(event.target.data);
    //Inspectthevalueofthesuccesselementnode
    if(success.toString( )=="1"){
    _message.text="Savedsuccessfully.";
    }else{
    _message.text="Errorencounteredwhilesaving.";
    }
    }catch(e:TypeError){
    //Displayanerrormessagesincetheserverresponsewasnotunderstood
    _message.text="CouldnotparseXMLresponsefromserver.";
    }
    }
    }
    }
  • 相关阅读:
    读取文本文件中的中文打印到Eclipse控制台为何显示问号
    使用StringUtils需要引用的依賴
    Ajax跨域访问XML数据的另一种方式——使用YQL查询语句
    AngularJS快速入门指南15:API
    国外社交网站获取分享数量APIs
    AngularJS快速入门指南14:数据验证
    AngularJS快速入门指南13:表单
    AngularJS快速入门指南12:模块
    AngularJS快速入门指南11:事件
    AngularJS快速入门指南10:DOM节点
  • 原文地址:https://www.cnblogs.com/tinytiny/p/2802774.html
Copyright © 2020-2023  润新知