怎样建网站 阿里云,wordpress groupon,烟台开发区建设局网站,红盾网官网入口1. AS3的事件机制 事件流机制即为捕获--目标--冒泡,分别对应event.eventPhase的值1(EventPhase.CAPTURING_PHASE)#xff0c;2(EventPhase.AT_TARGET)#xff0c;3(EventPhase.BUBBLING_PHASE) 假设有3个Sprite#xff0c;分别为绿、蓝、黄(如图),层叠关系为绿色包含蓝色2(EventPhase.AT_TARGET)3(EventPhase.BUBBLING_PHASE) 假设有3个Sprite分别为绿、蓝、黄(如图),层叠关系为绿色包含蓝色蓝色包含黄色 情况一最顶层的黄色有一个点击事件另外两个没有点击事件 结果target是--黄色方块,currentTarget是--黄色方块,阶段是--2 情况二三个Sprite都有一个点击事件,然后点击最上层的黄色方块 结果 target是--黄色方块,currentTarget是--黄色方块,阶段是--2 target是--黄色方块,currentTarget是--蓝色方块,阶段是--3 target是--黄色方块,currentTarget是--绿色方块,阶段是--3 可以看出来event的target始终是指单击的目标属于目标阶段而currentTarget指向处理事件(即活动)的目标属于冒泡阶段currentTarget属性应具备两个条件一是它注册了侦听器二是正在处理事件 {flash.display.Sprite;flash.events.MouseEvent;flash.text.TextField;flash.text.TextFieldAutoSize;Sample0413Sprite{lblInfo:TextField;Sample0413(){greenRect:Sprite Sprite();greenRect.graphics.beginFill(0x00FF00);greenRect.graphics.drawRect(100,100,200,200);greenRect.graphics.endFill();greenRect.addEventListener(MouseEvent.CLICK,onGreenClick);greenRect.name ;.addChild(greenRect);blueRect:Sprite Sprite();blueRect.graphics.beginFill(0x0000FF);blueRect.graphics.drawRect(130,130,150,150);blueRect.graphics.endFill();blueRect.addEventListener(MouseEvent.CLICK,onBlueClick);blueRect.name ;greenRect.addChild(blueRect);yellowRect:Sprite Sprite();yellowRect.graphics.beginFill(0xFFFF00);yellowRect.graphics.drawRect(160,160,100,100);yellowRect.graphics.endFill();yellowRect.addEventListener(MouseEvent.CLICK,onYellowClick);yellowRect.name ;blueRect.addChild(yellowRect);lblInfo TextField();lblInfo.background ;lblInfo.x 10;lblInfo.y 20;lblInfo.width 400;.addChild(lblInfo);}onGreenClick(event:MouseEvent):{.lblInfo.appendText();}onBlueClick(event:MouseEvent):{.lblInfo.appendText();}onYellowClick(event:MouseEvent):{.lblInfo.appendText();}onClick(event:MouseEvent):{targetStr:String (event.target Sprite).name;curTargetStr:String (event.currentTarget Sprite).name;phaseStr:String event.eventPhase;.lblInfo.appendText(targetStr curTargetStr phaseStr );}}
} 2. FocusEvent焦点事件 一共有4个焦点事件:FocusIn、FocusOut、KEY_FOCUS_CHANGE、MOUSE_FOCUS_CHANGE 当焦点改变时focusIn和focusOut 事件会同时激活它们属于不可取消的事件 keyFocusChange和mouseFocusChange是可取消的事件可以调用FocusEvent.preventDefault( )方法取消默认事件 FocusEvent有一个relatedObject属性对于focusIn而言relatedObject属性是刚才拥有焦点的对象的对于其它三个事件relatedObject属性是现在接收到焦点的对象 {flash.display.Sprite;flash.events.FocusEvent;flash.text.TextField;flash.text.TextFieldAutoSize;flash.text.TextFieldType;Sample0414Sprite{lblInfo:TextField;Sample0414(){textBox:TextField TextField();textBox.name ;textBox.type TextFieldType.INPUT;textBox.background ;textBox.width 200;textBox.height 20;textBox.addEventListener(FocusEvent.KEY_FOCUS_CHANGE,onKeyFocusChange);.addChild(textBox);textBox TextField();textBox.name ;textBox.type TextFieldType.INPUT;textBox.background ;textBox.width 200;textBox.height 20;textBox.y 80;textBox.addEventListener(FocusEvent.KEY_FOCUS_CHANGE,onKeyFocusChange);.addChild(textBox);lblInfo TextField();lblInfo.y 200;lblInfo.autoSize TextFieldAutoSize.CENTER;.addChild(lblInfo);}onFocusIn(event:FocusEvent):{txt:TextField event.target TextField;txt.text txt.name;(event.relatedObject!null){lblInfo.text (event.relatedObject TextField).name;}}onFocusOut(event:FocusEvent):{(event.relatedObject!null){lblInfo.text (event.relatedObject TextField).name;}}onKeyFocusChange(event:FocusEvent):{txt:TextField event.target TextField;(txt.text ) {event.preventDefault();} (event.relatedObject!null){strRelatedObj:String (event.relatedObject TextField).name;lblInfo.text strRelatedObj;}}}
} 3. 监听用户输入的文本 通过TextEvent事件监听用户对文本框内容的修改如删除剪切插入或者拷贝等操作对文本框的每一次修改都会激活textInput事件可以通过event.preventDefault()取消显示输入的文本 {flash.display.Sprite;flash.events.TextEvent;flash.text.TextField;flash.text.TextFieldType;Sample0414Sprite{lblInfo:TextField;Sample0414(){textBox:TextField TextField();textBox.type TextFieldType.INPUT;textBox.background ;textBox.width 200;textBox.height 20;textBox.addEventListener(TextEvent.TEXT_INPUT,onTextInput);.addChild(textBox);}onTextInput(event:TextEvent):{(event.text.toLowerCase().indexOf()-1){event.preventDefault();}}}
} 4. 为TextField添加超链接 同设置样式一样也有三种方式实现直接加入标记、设置TextFormatter、设置CSS 设置TextFormatter: textBox:TextField TextField();
textBox.text ;
formatter:TextFormat TextFormat();
formatter.color 0xFF0000;
formatter.url ;
formatter.target ;
textBox.setTextFormat(formatter);
.addChild(textBox); 设置CSS: textBox:TextField TextField();
textBox.htmlText ;css:StyleSheet StyleSheet( );
css.parseCSS();
textBox.styleSheet css;.addChild(textBox); 5. 用超链接调用ActionScript代码 在一个链接地址前加上event:即可以响应TextEvent.LINK事件。TextEvent.text属性就是url的地址 {flash.display.Sprite;flash.events.TextEvent;flash.text.TextField;flash.text.TextFormat;Sample0414Sprite{Sample0414(){textBox:TextField TextField();textBox.addEventListener(TextEvent.LINK,onClickLink);textBox.htmlText ;formatter:TextFormat TextFormat();formatter.color 0xFF0000;formatter.url ;formatter.target ;textBox.setTextFormat(formatter);textBox.addEventListener(TextEvent.LINK, onClickLink);.addChild(textBox);}onClickLink(event:TextEvent):{(event.text);}}
} 6. 高级文本布局 TextField 类定义了一系列API用于精确控制文本布局 getCharIndexAtPoint(x,y) -- 得到坐标(x,y)下的字符 getCharBoundaries(index) -- 得到索引index对应字符的Rectangle numLines属性 -- 得到TextField的文本行数 getLineIndexAtPoint(x,y) -- 得到坐标(x,y)下对应的行索引 getLineIndexOfChar(index) -- 得到索引index对应字符的行索引 getLineLength(lineIndex) -- 得到索引lineIndex对应行的字符数 getLineText(lineIndex) -- 得到索引lineIndex对应行的文本 getLineOffset(lineIndex) -- 得到索引lineIndex对应行的第一个字符的索引 getLineMetrics(lineIndex) -- 得到索引lineIndex对应行的度量信息包括x,width,leading,height,descent,ascent相关属性 getFirstCharInParagraph(index) -- 如果给定一个字符索引index,则返回同一段落中第一个字符的索引 getParagraphLength(index) -- 如果给定一个字符索引则返回包含该字符的段落的长度 {flash.display.Sprite;flash.events.MouseEvent;flash.text.TextField;flash.text.TextFieldType;Sample0421Sprite{label:TextField;Sample0421(){textBox:TextField TextField();textBox.type TextFieldType.INPUT;textBox.multiline ;textBox.htmlText ;textBox.addEventListener(MouseEvent.CLICK,onClick);textBox.background ;textBox.wordWrap ;.addChild(textBox);label TextField();label.background ;label.x 150;label.width 250;label.height 300;.addChild(label);}onClick(event:MouseEvent):{txt:TextField event.target TextField;label.text ;{label.appendText(txt.numLines);label.appendText( txt.getLineIndexAtPoint(mouseX,mouseY));label.appendText( txt.getLineIndexOfChar(20));label.appendText(txt.getLineLength(2));label.appendText(txt.getLineText(2));label.appendText(txt.getLineOffset(2));label.appendText(txt.getLineMetrics(2).width);label.appendText( txt.getFirstCharInParagraph(5));label.appendText( txt.getParagraphLength(3));(txt.text.charAt(5));}(ex:Error){label.text ex.message;}}}
} 7. 高级抗锯齿 对于嵌入字体可通过设置文本框的antiAliasType属性为flash.text.AntiAliasType.ADVANCED然后设置gridTypeFit和sharpness属性 flash.text.AntiAliasType.NORMAL -- 应用常规文本消除锯齿功能。 这与 Flash Player 7 和更早版本中使用的消除锯齿类型匹配。 应用高级消除锯齿功能这增加了文本的可读性。 此功能在 Flash Player 8 中可用。 高级消除锯齿功能可以高品质呈现小尺寸的字体。 它最适合在具有大量小字号文本的应用程序中使用。 建议不要对大于 48 磅的字体使用高级消除锯齿功能 gridFitType属性用于此文本字段的网格固定类型,仅在文本字段的 flash.text.AntiAliasType 属性设置为 flash.text.AntiAliasType.ADVANCED 时才应用此属性 flash.text.GridFitType.NONE -- 指定无网格固定。 不强制根据像素网格调整字型中的水平线和垂直线。 此设置通常适合动画或大号字。 flash.text.GridFitType.PIXEL -- 指定粗水平线和垂直线适合像素网格。 此设置仅适用于左对齐文本字段。 若要使用此设置文本字段的 flash.dispaly.AntiAliasType 属性必须设置为 flash.text.AntiAliasType.ADVANCED。 此设置通常能为左对齐文本提供最佳可读性。 flash.text.GridFitType.SUBPIXEL -- 指定粗水平线和垂直线适合 LCD 显示器上的子像素网格。 若要使用此设置文本字段的 flash.text.AntiAliasType 属性必须设置为 flash.text.AntiAliasType.ADVANCED。 flash.text.GridFitType.SUBPIXEL 设置通常适合右对齐或居中的动态文本有时为了在动画与文本品质之间达到一种平衡也可使用此设置。 sharpness 属性范围在-400 到400默认为0 它决定字体外框的清晰程度。值越低越模糊越高越锐利。当文字比较模糊时可以设置gridFitType 为PIXEL 或SUBPIXEL 以提高清晰度 8. 替换文本 使用replaceSelectedText(newText)方法替换选中的文字或用replaceText(startIndex,endIndex,newText)方法替换某一范围的文字 {flash.display.Sprite;flash.events.KeyboardEvent;flash.text.TextField;flash.text.TextFieldType;Sample0422Sprite{Sample0422(){textBox:TextField TextField();textBox.type TextFieldType.INPUT;textBox.background ;.addEventListener(KeyboardEvent.KEY_DOWN,onKeyDown);.addChild(textBox);}onKeyDown(event:KeyboardEvent):{(event.keyCode 13){txt:TextField event.target TextField;txt.replaceSelectedText();txt.replaceText(0,2,);}}}
} 9. 获取可用字体列表 Font.enumerateFonts(bool)方法返回可用字体列表参数默认为false,将返回一个只包括嵌入字体的列表;为true则返回一个包括所有字体(设备字体和嵌入字体)的列表 {flash.display.Sprite;flash.text.Font;[Embed(source,fontName,mimeType)]Sample0422Sprite{Sample0422(){allFonts:Array Font.enumerateFonts(); allFonts.sortOn(, Array.CASEINSENSITIVE);for (i:uint0; iallFonts.length; i){ (allFonts[i].fontName);} }}
} 10. 改变颜色 先获取可视化对象的obj.transform.colorTransform对象然后修改该对象再重新赋值给对象 设置颜色可以直接设置ColorTransform.color属性也可以分开设置redOffset,greenOffset,blueOffset和alphaOffset取值范围是-255到255(alpha 值范围在0 到100,与alphaOffset是不同的) {flash.display.Shape;flash.display.Sprite;flash.geom.ColorTransform;Sample0422Sprite{Sample0422(){rect:Shape Shape();rect.graphics.beginFill(0xFF0000);rect.graphics.drawRect(100,100,150,100);rect.graphics.endFill();.addChild(rect);ct:ColorTransform rect.transform.colorTransform;ct.redOffset 128;ct.greenOffset 128;ct.blueOffset 128;ct.alphaOffset 50;rect.transform.colorTransform ct;}}
} 转载于:https://www.cnblogs.com/CoderWayne/archive/2010/07/15/1778065.html