加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

flash学习笔记(四)--事件机制和用户界面学习

发布时间:2020-12-15 06:16:02 所属栏目:百科 来源:网络整理
导读:第九章 事件处理和基本的交互控制 1.????????基本事件处理: 事件源eventSource、事件名eventName、响应eventResponse Function eventResponse (eventObject:EventType):void{ ?//这里是为响应事件的步骤 } eventSource .assEventListener( Event_name ,

第九章 事件处理和基本的交互控制

1.????????基本事件处理:

事件源eventSource、事件名eventName、响应eventResponse

Function eventResponse(eventObject:EventType):void{

?//这里是为响应事件的步骤

}

eventSource.assEventListener(Event_name,eventResponse);

对于eventObject,对象变量

2.????????currentTarget和target属性:

currentTarget:代表当前正在操作对象àevt.currentTarget.name

target:当对象重合时,可能触发其子对象,所以会有误差,尽量使用currentTarget

3.????????addEventListener参数详解:

addEventListener(eventName,functionName,true/false,int,true/false);

?动作,函数名,动作捕抓流活动状态,优先级,不需要时是否在内存清掉

注意:捕获阶段捕获后就没有目标阶段,想要目标阶段必须第三个函数设置为false

????? 到达目标阶段后必须冒泡

4.????????可以用的基本交互事件:

Click/doubleClick/focusIn/focusOut/keyDown/keyFocusChage/mouseMove/MouuSEOut/mouSEOver/mouseUp/mouseWheel/rollout/rollOcer/tabChildrenChange/tabEnabledChage/tabIndexChang

5.????????相应键盘事件:

1>????functionkeyhandler(evt:KeyboardEvent):void{

?evt.charCode:按下键的字符代码

?evt.keyCode:按下键的数字代码

?evt.keyLocation:区分左shift和右shift;标准键盘和数字键盘

?evt.altKey:是否按下

?evt.ctrlKey:是否按下

?evt.shiftKey:是否按下

}

this.stage.addEventListener(KeyboardEvent.KEY_DOWN,keyhandler);

2>????if(evt.keyCode== Keyboard.RIGHT)

evt.currentTarget.x? =?evt.currentTarget.x + 10;

Stage.focus = myMovieClip;

注意查看:Keyboard类的常数

3>????fullScreen事件

若要启用全屏模式,请将allowFullScreen参数添加到包含SWF文件的HTML页中的object和embed标签,同时将allowFullScreen设置为"true",如下例所示:

<paramname="allowFullScreen"value="true"/>

给swf增加一个全屏按钮:fullBt
代码如下:

fullBt.addEventListener(MouseEvent.CLICK,fullscreenshow);

functionfullscreenshow(evt:MouseEvent):void{
switch(stage.displayState){
case"normal":
stage.displayState="fullScreen";
break;
case"fullScreen":
default:
stage.displayState="normal";
break;
}}

4>????组合键:evt.shiftKey&&evt.keyCode==79

Stage.stageFocusRect = false;?
指定对象在具有焦点时是否显示加亮的边框。

5>????Mouse.hide()/Mouse.show();

6.????????自定义Flash Player右键菜单:

1>????首先实例化ContextMenuItem:用来保存每个项目

Var myContextMenuItem:ContextMenuItem= new ContextMenuItem(caption,分割线,enabled,visible);

2>????实例化ContextMenu:用来保存右键菜单:

Var myContextMenu:ContextMenu =new ContextMenu();

3>????将项目放到右键菜单中:

myContextMenu.hideBuiltInItems();

myContextMenu.customItems.push(myContextMenuItem);

4>????将菜单赋给对象:

This.contextMenu = myContextmenu;

5>????添加监听:

MyContextMenuItem.addEventLIstener(ContextMenuEvent.menuItemSelect,处理事件);

第十章 设计用户界面和使用组件

1.??????使用TextField动态设置文本框失败!----第二天成功

scroll_txt.txt.scrollV -= 1;

当textfield转化为MC后,调用应注意子对象!

2.??????使用TextFormat动态设置文本格式:

Var myTextFormat:TextFormat = newTextFormat();

myTextFormat.bold = true;

myTextField.setTextFormat(myTextFormat);

3.??????使用HTML标签动态设置文本格式:

My_txt.htmlText = “<b>显示出粗体</b>”;

4.??????使用样式表动态设置文本格式:

1>css和html正常编写

2>加载并应用css:

Var cssReq:URLRequest =new URLRequest(“myCSS.css”);

Var cssLoader:URLLoader= new URLLoader();

FunctiononCSSFileLoader(evt:Event):void{

?VarmyStyleSheet:StyleSheet = new StyleSheet();

? myStyleSheet.parseCss(cssLoader.data);

? main_txt.stylesheet = myStyleSheet;

}

cssLoader.addEventListener(Event.COMPLETE,onCssFileLoader);

cssLoader.load(cssReq);

3>将html文档作为XML加载,并赋给文本框:

?Var myDoc:XMLDocument= new XMLDocument ();

? myDoc.ignorewhite = true;

? myDoc.parseXML(xmlLoader.data);

? main_txt.htmlText = myDoc.toString;

5.??????动态创建和使用文本框:WordWrap:文本是否自动换行;type:是否是动态文本

Var myTextField:TextField = newTextField();

6.??????消除嵌入字体的锯齿:TextRender

7.??????使用UIScrollBar创建滚动文本框:不能再元件上,在textField

8.??????改变组件外观:

1>创作阶段改变

2>运行时:component.setStyle()/getStyle()

3>单个组件实例:instanceName.setStyle(“propertyname”,”value”);

4>单个组件所有实例:StyleManager.setComponentStyle(Button,”textFormat”,tf);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读