给你的 Flash 动画增加一个 JavaScript 类,可以直接在 Flash 里面调用一些简单实用的 JavaScript 功能。(注意,Flash 文件要放在浏览器里面才可用)
作者:senocular
代码:(灰色的为一行)
Javascript = function(script){ if (arguments.length) this.setScript(script);}Javascript.broadcaster = Javascript.prototype.broadcaster = _level0.createEmptyMovieClip("JavascriptEnterFrame", 987654);Javascript.broadcaster.onEnterFrame = function(){ if (this.script.length) getURL("javascript:"+this.script+";void(0);"); this.script="";}Javascript.prototype.load = LoadVars.prototype.loadJavascript.prototype.onData = function(js){ if (js != undefined){ this.script = js; this.onLoad(true) }else this.onLoad(false);}Javascript.prototype.setScript = function(str){ this.script = str+";\n"; return this;}Javascript.prototype.run = Javascript.run = function(str){ if (!arguments.length) str = this.script; this.broadcaster.script += str+";\n";}Javascript.prototype.alert = Javascript.alert = function(str){ this.run("alert('"+str+"')");}Javascript.prototype.statusBar = Javascript.statusBar = function(str){ this.run("window.status='"+escape(str)+"'");}Javascript.prototype.windowSize = Javascript.windowSize = function(width,height){ this.run("window.resizeTo("+width+","+height+")");}Javascript.prototype.windowPosition = Javascript.windowPosition = function(x,y){ this.run("window.moveTo("+x+","+y+")");}Javascript.prototype.windowScroll = Javascript.windowScroll = function(x,y){ this.run("window.scrollTo("+x+","+y+")");}Javascript.prototype.openNewWindow = Javascript.openNewWindow = function(url, name, attribs){ this.run("window.open('"+url+"','"+name+"','"+attribs+"')");} 用法:拷贝上面的程序到 Flash 里面就可以使用了
JavascriptInstance = new Javascript("javascript"); Javascript instance Methods:
- setScript("javascript");
- load("url"); // 载入脚本
- run(["javascript"]);* // 运行脚本
- statusBar("string");* // 状态条文字
- windowSize(width,height);* // 窗口缩放
- windowPosition(x,y);* // 窗口定位
- windowScroll(x,y);* // 滚动窗口
- openNewWindow("url,"name","attributes");*
* 可以直接使用的(不需要创建实例)
js = new Javascript("alert('hello');");
js.run();
js.setScript("alert('world');").run();
js.statusBar("hello, I\\'m your statusBar");
js.windowSize(400,400);
Javascript.windowPosition(0,30);
Javascript.windowScroll(0,200);
Javascript.openNewWindow("http://www.ibm.com","home","width=550,height=400");
externalJS = new Javascript(); // 外部脚本
externalJS.onLoad = function(){
this.run();
}
externalJS.load("myjavascript.js"); // 运行外部脚本
Word教程网 | Excel教程网 | Dreamweaver教程网 | Fireworks教程网 | PPT教程网 | FLASH教程网 | PS教程网 |
HTML教程网 | DIV CSS教程网 | FLASH AS教程网 | ACCESS教程网 | SQL SERVER教程网 | C语言教程网 | JAVASCRIPT教程网 |
ASP教程网 | ASP.NET教程网 | CorelDraw教程网 |