Flash文本框限制只允许输入中文的方法 中文字符的编码为0x4E00-0x9FA5 方法一:在用户输入时对每个字符编码进行判断,看是否在0x4E00-0x9FA5这个范围内 方法二:利用输入文本的限制属性:restrict 可以写为: textInput.restrict=String.fromCharCode(0x4E00)+"-"+String.fromCharCode(0x9FA5); 也可以简单的写为: textInput.restrict="一-龥"; “一”和“龥”的编码分别对应为0x4E00和0x9FA5 _______________________________________________ 包含外部脚本写法 AS2 #include "script.as" AS3 include "script.as" _______________________________________________ 以xml形式打印对象 flash.utils.describeType(对象变量) _______________________________________________ flash取得包含该flash的当前页面地址的类 今天思考了一下flash取得包含该flash当前页面的地址的问题。 觉得可以用ExternalInterface与js通信来实现。而页面上不需要添加js代码,使用js的公共函数。 使用该判定后,可以禁止flash在其他不被允许的页面播放,当然,只是最初级的判定。 很简单的。直接帖代码。 AS2.0的代码 import flash.external.ExternalInterface; class GetHttpUrlIncludeThisSwf { public static function getHttpUrl() { return ExternalInterface.call("eval","window.location.href"); } } AS3.0的代码 package { import flash.external.ExternalInterface; public class GetHttpUrlIncludeThisSwf { public function GetHttpUrlIncludeThisSwf() { throw new Error("GetHttpUrlIncludeThisSwf class is static container only"); } public static function getHttpUrl() { return ExternalInterface.call("eval", "window.location.href"); } } } 将上面的代码保存为GetHttpUrlIncludeThisSwf.as即可 在flash里调用GetHttpUrlIncludeThisSwf.getHttpUrl()即可返回包含此swf的页面地址。 _______________________________________________ //加载图片 var pictLdr:Loader = new Loader(); pictLdr.load(new URLRequest("test.png")); addChild(pictLdr); //保存到本地对话框 var fileRef:FileReference=new FileReference(); fileRef.save(byteArray, "test.png"); _______________________________________________ //设置mybutton按钮组件样式 var tf:TextFormat = new TextFormat(); tf.font = "Arial"; tf.size = 16; tf.bold = true; mybutton.setStyle("textFormat", tf); //设置所有按钮组件样式 import fl.managers.StyleManager; import fl.controls.Button; var tf:TextFormat = new TextFormat(); tf.color = 0xFF0000; StyleManager.setComponentStyle(Button, "textFormat", tf); //设置所有组件样式 import fl.managers.StyleManager; var tf:TextFormat = new TextFormat(); tf.color = 0xFF0000; StyleManager.setStyle("textFormat", tf); _______________________________________________ Check connection in AS3 import air.net.URLMonitor; import flash.net.URLRequest; import flash.events.StatusEvent; var monitor:URLMonitor = new URLMonitor(new URLRequest('http://www.enginyoyen.com')); monitor.addEventListener(StatusEvent.STATUS, checkHTTP); monitor.start(); function checkHTTP(e:StatusEvent){ if(monitor.available){ test_txt.text ="Internet is available"; }else{ test_txt.text ="No internet connection available"; } } _______________________________________________ function displayInHex(c:uint):String { function extractRed(c:uint):uint { return (( c >> 16 ) & 0xFF); } function extractGreen(c:uint):uint { return ( (c >> 8) & 0xFF ); } function extractBlue(c:uint):uint { return ( c & 0xFF ); } function combineRGB(r:uint,g:uint,b:uint):uint { return ( ( r << 16 ) | ( g << 8 ) | b ); } var r:String=extractRed(c).toString(16).toUpperCase(); var g:String=extractGreen(c).toString(16).toUpperCase(); var b:String=extractBlue(c).toString(16).toUpperCase(); var hs:String=""; var zero:String="0"; if (r.length==1) { r=zero.concat(r); } if (g.length==1) { g=zero.concat(g); } if (b.length==1) { b=zero.concat(b); } hs=r+g+b; return hs; } _______________________________________________ //Use this to dynamically copy objects. my copyFunction(value:Object):Object{ var buffer:ByteArray = new ByteArray(); buffer.writeObject(value); buffer.position = 0; var result:Object = buffer.readObject(); return result; }