//---------------------------------------------------------------------------------------------- //【FLASH实现设为首页、加入收藏、打开一个制定的新窗口】 //设为首页: getURL("javascript :void(document.links[0].style.behavior='url(#default#homepage)');void document.links[0].setHomePage('http://www.flashempire.com/&;#39;);", "_self", "POST"); //加入收藏夹: getURL("javascript :void window.external.AddFavorite('http://www.flash8.net&;#39;,'闪吧');", "_self", "POST"); //定制弹出窗口: getURL("java script:window.open('new.htm','newwin','width=320,height=320');") //---------------------------------------------------------------------------------------------- //【用鼠标画线】 onMouseDown = function () { lineStyle(2, 0*000000, 100); lineTo(_xmouse, _ymouse); }; onMouseMove = function () { if (a) { lineStyle(2, 0x000000, 100); // 指定线条的粗度为2,颜色为黑色,透明度为100; lineTo(_xmouse, _ymouse); // 画线至鼠标所在位置; } updateAfterEvent(); // 强制刷新;Flash 强制进行显示刷新工作。该语句不依赖于时间帧的触发。 }; onMouseDown = function () { a = true; // 鼠标按下,给a变量赋值true,即执行上面的if后面括号内的语句,开始画线; moveTo(_xmouse, _ymouse); // 重新定位开始点; }; onMouseUp = function () { a = false; }; // 鼠标松开,给a变量赋值false,不执行上面的if后面括号内的语句,停止画线; //---------------------------------------------------------------------------------------------- //【将矩形影片剪辑作为遮罩图形】 //在load事件中,用变量xs和ys取得影片剪辑初始状态下的宽度和高度值。在enterFrame事件中,计算鼠标位置与矩形影片剪辑中心的距离,算出它与矩形宽度和高度值的比值,然后作为_xscale和_yscale的值。该动画实现移动鼠标位置以改变遮罩效果 //矩形影片剪辑中代码: onClipEvent (load) { xs = _width; ys = _height; } onClipEvent (enterFrame) { _xscale = 100*(_root._xmouse-_x)/(xs/2); _yscale = 100*(_root._ymouse-_y)/(ys/2); } //---------------------------------------------------------------------------------------------- //【实现倒放】 onClipEvnt(load){ gotoAndStop("endFrame"); //影片载入时就跳转到最后一帧并停止 } onClipEvent(enterFrame){ prevFrame(); //不断的播放前一桢 } //---------------------------------------------------------------------------------------------- //【isNaN 函数】 isNaN(expression:Object) : Boolean //值为 NaN(非数字),则返回 true //---------------------------------------------------------------------------------------------- //【检查E-MAIL的函数】 function checkEmail(str:String):Boolean { var arr = str.split("@"); var aIdx = str.indexOf("@"); var dotIdx = arr[1].indexOf("."); if ( arr.length != 2 || aIdx<1 || dotIdx<1 || dotIdx==arr[1].length-1 ) { return false; } else { return true; } } //---------------------------------------------------------------------------------------------- //【保留小数】 //这样是保留一位,乘上100就是两位 int(你的数*10)/10; //---------------------------------------------------------------------------------------------- //【flash5脚本实现关机】 fscommand ("exec","rundll"+chr(9)+"user.exe,exitwindows"); //---------------------------------------------------------------------------------------------- //【鼠标键】 左键: Key.isDown(1) 右键: Key.isDown(2) 左键: Key.isToggled(1) 右键: Key.isToggled(2) 滚轮: Key.isToggled(4) 滚轮1: Key.isToggled(4) PC机上用 滚轮2: Key.isToggled(3) MAC机上用 未知: Key.isToggled(3) //---------------------------------------------------------------------------------------------- //【实现TAB功能】 按钮能像window那样用Tab键来转换选择,用button.onKillFoucus numarray=new array("_root.text1","_root.text2",....................."_root.textn"); //把这个N个文本框做组成一个数组 x=Selection.getfocus(); // x 获得鼠标焦点的一个字符串 for(i=0;i<=n;i++){ //首先获得鼠标焦点 if(numarray[i]==x){ num=i; } //获得当前焦点在数组中的位置 } on (keyPress "") { //然后编写TAB键功能 num==n ? num=0 : num++; Selection.setfocus(numarray[num]); } //---------------------------------------------------------------------------------------------- //【动态文本设置alpha函数】 function setAlpha(obj, alpha) { var rgb = "0x"+(255*(100-alpha)/100).toString(16); rgb = rgb << 16 | rgb << 8 | rgb; obj.backgroundColor |= rgb; obj.borderColor |= rgb; obj.textColor |= rgb; } //usage this.createTextField("txt", 0, 0, 0, 100, 20); txt.textColor = 0xFF0000; txt.text = "samstudio"; setAlpha(txt, 50); //---------------------------------------------------------------------------------------------- //【拒绝影片被装载】 //拒绝影片被人用loadMovie导入,以下as一定要设在_root最上层桢动作第一行 this._name = "nn"; this.onEnterFrame = function() { if (this._name != "nn" || this.getDepth() != -16384) { this.unloadMovie(); } }; //---------------------------------------------------------------------------------------------- //【装载网页代码】 System.useCodepage = true; var url:String = "http://www.google.com/search?hl=zh-CN&q=flash"; var pageStr:LoadVars = new LoadVars(); pageStr.load(url); pageStr.onData = function(data) { t_txt.text = data; }; this.createTextField("t_txt", 0, 0, 0, Stage.width, Stage.height); t_txt.wordWrap = true; //---------------------------------------------------------------------------------------------- //【SharedObject】 var myLSO:SharedObject = SharedObject.getLocal ("foo"); if (myLSO.data.myObj == undefined) { myLSO.data.myObj = {fname:"Jessica",lname:"Smith"}; } else { var firstname:String = myLSO.data.myObj.fname; var lastname:String = myLSO.data.myObj.lname; } //---------------------------------------------------------------------------------------------- //【弹性形变】 //三个参数,scale: 图片的比例 frequency: 弹性的频率 quotiety: 弹性系数 MovieClip.prototype.tempo = 0; MovieClip.prototype.jump = function(scale, frequency, quotiety) { this.tempo += (scale-this._xscale)*frequency; this.tempo *= quotiety; this._xscale = this._yscale += this.tempo; }; mc.onEnterFrame = function() { if (this.hitTest(_xmouse, _ymouse, true)) { this.jump(70, .9, .6); } else { this.jump(30, .6, .5); } };