从flashVars将文本设置到剪贴板

时间:2013-03-21 17:28:16

标签: html actionscript-3 flash actionscript actionscript-2

我想做什么: 获取Flash Var,将flashVar设置为ClipBoard HTML:

<embed src="setClip.swf" FlashVars="res=123" quality="high" TYPE="application/x-shockwave-flash">

动作脚本(3):

function loaderComplete(myEvent:Event)
{
   this.flashVars=this.loaderInfo.parameters;
   this.flashVarsLoaded=true;
   this.useFlashVars();
}
function useFlashVars()
{
        aaa.text = myFlashVars.res;
}
var myFlashVars=new Object();
myFlashVars.flashVarsLoaded=false;
myFlashVars.loaderComplete=loaderComplete;
myFlashVars.useFlashVars=useFlashVars;
this.loaderInfo.addEventListener(Event.COMPLETE, myFlashVars.loaderComplete);

当我打开html页面时,“aaa”输入中没有文字 什么是获取 flash var 然后将他插入剪贴板(as1,as2,as3)的最佳方法(我需要好的示例)?

1 个答案:

答案 0 :(得分:1)

您无需等待flashvars加载并使用Event.COMPLETE。玩家启动时Flashvars位于主类loaderInfo.parameters中。只需尝试在主类中跟踪它trace (this.loaderInfo.parameters["res"])

1创建新的fla文件,保存它

2添加到舞台文本字段(动态),设置实例名称ft1

3单击主要阶段,在属性面板中,类类型main

4在带有fla的dir中创建main.as(步骤1)

5 main as:

package  {

    import flash.display.MovieClip;
    public class main extends MovieClip {
        public function main() {
            tf1.text = this.loaderInfo.parameters["foo"];
        }
    }
}

6文件 - &gt;发布

7转到dir(步骤1),打开.html文件,添加行 <param name="flashvars" value="foo=10" /> 在params(两次)

8在浏览器中打开HTML,享受

(注意:您无法在Adobe Flash IDE环境中测试flashvars,在真实浏览器中测试olny)

关于剪贴板: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/system/System.html#setClipboard() This method works from any security context when called as a result of a user event (such as a keyboard or input device event handler).

9添加按钮进入舞台,将其命名为btn

10 main.as:

package  {
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.system.System;

    public class main extends MovieClip {
        public function main() {
            tf1.text = loaderInfo.parameters["foo"];
            btn.addEventListener(MouseEvent.CLICK, onClickHandler);
        }

        private function onClickHandler(e:MouseEvent):void {
            System.setClipboard(loaderInfo.parameters["foo"]);
        }
    }
}

11编译.fla,在浏览器中打开HTML,单击btn,检查剪贴板

抱歉,无法在没有用户互动的情况下“自动”填充剪贴板。请记住:读取和写入剪贴板是一个巨大的安全漏洞。