ITeye博客

[转]FLASH与JS序列简单应用

AS3 · 2011-10-28 01:03 · 文章转载 · 问题总结 · SWF格式 · AS3常用开源库 · 源码范例 · Web前端 · Markdown

FLASH与JS序列简单应用 (一) 用swfobject简单插入SWF

  1. <script type="text/javascript">
  2. var so = new SWFObject("focus.swf", "flash", "100%", "100%", "9");
  3. so.write("flashcontent");
  4. function onFocus(){
  5. document.getElementById("flash").focus();
  6. }

复制代码

 

 

 

 

 

FLASH与JS序列简单应用 (二) JS给FLASH传值

  1. var so=new SWFObject("fl.swf","flash","800","600","9");
  2. so.write("flashcontent");
  3. function callFlash(){
  4. document.getElementById("flash").showTxt(Math.random());
  5. }

复制代码

 

 

 

 

 

 

 

 

FLASH与JS序列简单应用 (三) JS隐藏与显示FLASH

  1. <script>
  2. var so=new SWFObject("index.swf","flash","100%","100%","10");
  3. var btn=document.getElementById("showBtn");
  4. function showFlash(){
  5. if(btn.innerHTML=="运行"){
  6. so.write("flashcontent");
  7. btn.innerHTML="关闭";
  8. }else{
  9. hideFlash();
  10. }
  11. }
  12. function hideFlash(){
  13. document.getElementById("flashcontent").innerHTML="";
  14. btn.innerHTML="运行";
  15. }
  16. function seeFlash(){
  17. var _div=document.getElementById("flashcontent");
  18. var _btn=document.getElementById("seeBtn");
  19. if(_div.style.display=="none"){
  20. _div.style.display="";
  21. _btn.value="隐藏";
  22. }else{
  23. _div.style.display="none";
  24. _btn.value="显示";
  25. }
  26. }
  27. showFlash();
  28. </script>

复制代码

 

 

 

 

 

 

FLASH与JS序列简单应用 (四) AS通过JS读取cookie

  1. function getCookie(objName){//获取指定名称的cookie的值
  2. var arrStr = document.cookie.split("; ");
  3. for(var i = 0;i < arrStr.length;i ++){
  4. var temp = arrStr[i].split("=");
  5. if(temp[0] == objName) return unescape(temp[1]);
  6. }
  7. }

复制代码

 

 

 

 

 

 

 

 

 

FLASH与JS序列简单应用 (五) 根据焦点禁止或者启用滚动

  1. <script type="text/javascript">
  2. function onMouseScroll(e){
  3. if (e.preventDefault) e.preventDefault();
  4. }
  5. function changeFocus(){
  6. var _fl=document.getElementById("flash");
  7. if(document.activeElement==_fl){
  8. if(window.addEventListener){
  9. window.addEventListener("DOMMouseScroll",onMouseScroll,true);
  10. }else{
  11. document.onmousewheel=onMouseScroll;
  12. }
  13. }else{
  14. if(window.addEventListener){
  15. window.attachEvent("DOMMouseScroll",onFFscroll);
  16. }else{
  17. document.onmousewheel=null;
  18. }
  19. }
  20. //setTimeout(changeFocus,2000);
  21. }
  22. setInterval(changeFocus,300);
  23. var so = new SWFObject("focus.swf", "flash", "100%", "1000", "9");
  24. so.write("flashcontent");
  25. </script>

复制代码

 

 

 

 

 

 

 

 

FLASH与JS序列简单应用 (六) FLASH右键替换

  1. <script type="text/javascript">
  2. var so = new SWFObject("FL.swf", "flash", "800", "600", "9", "#CCCCCC");
  3. so.addParam("wmode", "opaque");
  4. so.write("flashcontent");
  5. function callFlash(){
  6. //alert("触发FLASH中的右键替代函数");
  7. document.getElementById("flash").onClick();
  8. }
  9. if(window.addEventListener){
  10. window.addEventListener("mousedown",function(e){
  11. if(e.button==2){
  12. callFlash();
  13. //屏蔽右键
  14. if (e.stopPropagation) e.stopPropagation();
  15. if (e.preventDefault) e.preventDefault();
  16. if (e.preventCapture) e.preventCapture();
  17. if (e.preventBubble) e.preventBubble();
  18. }
  19. },true);
  20. }else{
  21. document.getElementById("flashcontent").onmousedown=function(){
  22. if(event.button==2){
  23. callFlash();
  24. //屏蔽右键
  25. document.oncontextmenu=function(){return false;};
  26. this.setCapture();
  27. this.onmouseup=function(){
  28. this.releaseCapture();
  29. }
  30. }
  31. }
  32. }
  33. </script>

复制代码

 

 

 

 

 

 

 

 

FLASH与JS序列简单应用 (七) FLASH中键检测与右键屏蔽

  1. <script type="text/javascript">
  2. var so = new SWFObject("FL.swf", "flash", "800", "600", "9", "#CCCCCC");
  3. so.addParam("wmode", "opaque");
  4. so.write("flashcontent");
  5. function callFlash(){
  6. //alert("中键");
  7. document.getElementById("flash").onClick();
  8. }
  9. if(window.addEventListener){
  10. window.addEventListener("mousedown",function(e){
  11. if(e.button==1)callFlash();
  12. //屏蔽右键
  13. if(e.button==2){
  14. if (e.stopPropagation) e.stopPropagation();
  15. if (e.preventDefault) e.preventDefault();
  16. if (e.preventCapture) e.preventCapture();
  17. if (e.preventBubble) e.preventBubble();
  18. }
  19. },true);
  20. }else{
  21. document.getElementById("flashcontent").onmousedown=function(){
  22. if(event.button==4)callFlash();
  23. //屏蔽右键
  24. if(event.button==2){
  25. document.oncontextmenu=function(){return false;};
  26. this.setCapture();
  27. this.onmouseup=function(){
  28. this.releaseCapture();
  29. }
  30. }
  31. }
  32. }
  33. </script>

复制代码

 

 

 

 

 

 

 

FLASH与JS序列简单应用 (八) JS与AS互相通信

  1. <script type="text/javaScript">
  2. var so = new SWFObject("ExternalInterfaceExample.swf", "flash", "550", "400", "9");
  3. so.write("myId");
  4. var jsReady = false;
  5. function isReady() {
  6. return jsReady;
  7. }
  8. function pageInit() {
  9. jsReady = true;
  10. document.forms["form1"].output.value += "\n" + "JavaScript is ready.\n";
  11. }
  12. function sendToActionScript(value) {
  13. document.getElementById("flash").sendToActionScript(value);
  14. }
  15. function sendToJavaScript(value) {
  16. document.forms["form1"].output.value += "ActionScript says: " + value + "\n";
  17. }
  18. </script>

复制代码

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。