主题:  网页脚本与Actionscript互相传递变量实例

janlay

职务:管理员
等级:7
金币:28.0
发贴:7244
注册:2003/11/27 18:07:11
#12002/10/29 0:03:43
近日在制作留言本的过程中,做了一个javacript & actionscript交互的应用。其中,涉及到网页脚本控制flash动画的内容。我想,应该会有人对这个感兴趣的。出于这个原因,现在把它简化成一个示例如下:


页面:点这儿参观

 全部文件提供下载

编辑历史:[这消息被janlay编辑过(编辑时间2003-01-17 14:14:22)]


5D限制级

职务:普通成员
等级:6
金币:10.0
发贴:4970
注册:2001/8/16 14:52:34
#22002/10/29 0:35:08
妙不可言
参数传递主要是在网页上的颜色块和选取颜色的配色器里作用吧



janlay

职务:管理员
等级:7
金币:28.0
发贴:7244
注册:2003/11/27 18:07:11
#32002/10/30 9:22:59
是的。从网页向SWF传用到了swfid.SetVariable(),传回来则是通过fscommand的args.



s22

职务:版主
等级:4
金币:10.0
发贴:1634
注册:2004/12/19 13:06:46
#42002/11/2 4:01:29
Copy a text from Flash to to the sytem clipboard

I have found out that in order to copy a text from Flash to to the sytem clipboard we need a visible textarea, if we don't have it, we get an empty string. But in order to copy from clipboard to Flash we don't need a visible textarea (a hidden textarea is enough). This rule applies to the IE4 and above version, but I have written a IE 5 and above version which is much more simple and doesn't require any textareas.
Here is some background info for people interested in this subject.

In the Flash movie we have a dynamic text area with the variable name "text". We copy the clipboard content from and into it.
There is a button (copy) with that action:

on (release) {
var myText = _root.text;
getURL ("javascript:flashToClipBoard('"+myText+"'); void(0);");
}

When the button Copy is pressed the text in the dynamic textbox is passed as the argument of our javascript function.
I have posted the HTML code here:
//************************************IE4 and above version************************************//


Flash To Clipboard




















The text in the clipboard will appear here.

You can open a text editor program (e.g. Notepad) and paste the text there.











codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
WIDTH=500 HEIGHT=350 ID="movie">


NOTE: If the text you have copied in Flash has carriage returns you cannot copy it back to the clipboard.

Here is some text that you can copy to the clipboard

(Choose Edit>Copy or right-click and copy).



'Twas brillig, and the slithy toves

Did gyre and gimble in the wabe:

All mimsy were the borogoves,

And the mome raths outgrabe.







//************************************************************************//

If we don't use any form we can omit the id reference of the form in our scripts. The first form (id="pasteHere") is used to display the clipboard content, so you can do without it. flashToClipBoard function works fine when the textarea "hiddenBox" is not displayed.

function flashToClipBoard(flashInput) {
// the argument of this function is passed from Flash
hiddenBox.innerText = flashInput;
copiedText = hiddenBox.createTextRange();
copiedText.execCommand("Copy");
}

But the second function (flashToClipBoard) requires the textarea to be displayed (Style="display:none") will give us an empty string. (We cannot use a hidden textarea for that function)

But if we don't care for IE4.x browsers and we want to write a script for IE 5 and above browsers, things are much more easy for us. Here is the version for IE 5 and above:
(You can use the same Flash movie in that example)
//************************************IE5 and above version************************************//


Flash To Clipboard





codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
WIDTH=500 HEIGHT=350 ID="movie">


NOTE: If the text you have copied in Flash has carriage returns you cannot copy it back to the clipboard.

Here is some text that you can copy to the clipboard

(Choose Edit>Copy or right-click and copy).



'Twas brillig, and the slithy toves

Did gyre and gimble in the wabe:

All mimsy were the borogoves,

And the mome raths outgrabe.







//************************************************************************

Netscape requires a trusted script to give access to the system clipboard. I have figured out the basic structure of such a script but (as I am not a Java programmer) I couldn't find out the exact syntax to instantiate the Java object and use its methods. Probably it should look like this



If someone knows the JAVA syntax and can post it on FORUMS, it would be nice.
It is also interesting that such a widely used browser as Internet Explorer 5.x has such a few security restrictions (regarding the clipboard access).


//actionscripts.org

转过来的