flash中as与js交互

      前段时间一直搞活动页面,趁着有空闲的时间总结下as跟js之间的交互。

      首先来段as的代码。

 

package  {
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.external.ExternalInterface;
	
	public class TestAs extends MovieClip {
		
		public function TestAs() {
			bindAllEvent();
			init();
		}
		
		private function init():void{
			btn1.label = "按我吧";
			ExternalInterface.addCallback("callASMethod", callASMethod);
		}
		
		private function bindAllEvent():void{
			btn1.addEventListener("click", btn1Handler);
		}
		
		private function btn1Handler(event:Event):void{
			callJSMethod();
		}
		
		//js调用as
		private function callASMethod(value:String):void{
			btn1.label = value;
		}
		
		//as调用js代码
		private function callJSMethod():void{
			ExternalInterface.call("callJSMethod", "测试下");
		}
	}
	
}

 代码很简单,上面只有一个按钮btn1,定义了两个方法,主要用来给js跟as交互的。

 

  页面代码:

<html>
<head>
<title>as与js交互</title>
</head>
<body>
	<input type="button" value="调用flash方法" onclick="sendToAS()"/>
	<div id="swfcontent"></div>
<script type="text/javascript">
	function insertFlash(elm, eleid, url, w, h, b) {
		if (!document.getElementById(elm)) return;
		var str = '';
		str += '<object width="' + w + '" height="' + h + '" id="' + eleid + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=10,0,0,0">';
		str += '<param name="movie" value="' + url + '" />';
		str += '<param name="allowScriptAccess" value="always" />';
		str += '<param name="base" value="' + b + '" />';
		str += '<param name="wmode" value="transparent" />';
		str += '<param name="quality" value="autohigh" />';
		str += '<embed width="' + w + '" base="' + b + '" height="' + h + '" name="' + eleid + '" src="' + url + '" quality="autohigh" swLiveConnect="always" wmode="transparent" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>';
		str += '</object>';
		document.getElementById(elm).innerHTML = str
	}
	var base = "";//指针及抽奖图片背景所在路径
	insertFlash("swfcontent", "Lottery", "1.swf", 500, 400, base);

	//as调用js方法
	function callJSMethod(msg){
		alert(msg);
	}

	 function getMovie(movieName) {
		 if (navigator.appName.indexOf("Microsoft") != -1) {
			 return window[movieName];
		 } else {
			 return document[movieName];
		 }
	 }
	 
	//js调用as方法
	function sendToAS() {
		getMovie("Lottery").callASMethod("js调用flash");
	}
</script>
</body>
</html>

  flash跟页面各有一个按钮,html页面的按钮点击后会访问as上的方法,而flash上按钮点击后会调用js上的方法。

Flash(AS3)与JS相互调用 自制的,两个简单实例实现Flash与JS的相互调用与传值,仅实现基本功能,可在此原理基础上对函数进行拓展,例如使用Flash封装网页数据等。 在AS代码中附有简单注释解释程序。 ======== 简 单 介 绍 ======== 1、Flash调用JS传递数据: 通过ExternalInterface.call()方法,在Flash中调用JS函数。 通过调用带参的JS函数实现Flash向JS传值,通过调用带返回值的JS函数实现JS向Flash传值。 2、JS调用Flash传递数据: 通过ExternalInterface.addCallback()方法,创建函数接口,实现JS调用Flash函数。 创建接口后,在JS中调用Flash函数并向函数传值。 ======== 注 意 事 项 ======== 1、请打开文件夹中的html文件查看结果。 2、对于传统ExternalInterface.addCallback()方法(即JS调用Flash传递数据实例),存在浏览器兼容性问题。请使用IE浏览器打开html文件方可查看运行结果。 立即下载

相关推荐

锂电池主动均衡理解

锂电池主动均衡方案总结: 来自:http://wenku.baidu.com/link?url=EWiyACZ3aLPhcOjI4FZL3uQ9d0FD6dBhADQSVQiaSmRHHATTdSig1Wy39JY7-ijCzbAEYG1ymz6Lv5zhGdZaStQSHzFt6v3h3_tMrJudz9O 目前车厂采用被动均衡方案的公司:(来自网页) 目前采用主动均衡的...

weixin_34365417的博客 2916

js与as的交互

<br />javascript与actionscript进行交互主要是通过ExternalInterface类来进行的。<br />官方对于ExternalInterface的描述如下:<br />ExternalInterface 类是外部 API,这是一个在 ActionScript 和 Flash Player 容器之间实现直接通信的应用程序编程接口,例如,包含 JavaScript 的 HTML 页。Adobe 建议使用 ExternalInterface 实现 JavaScript 与 Acti

xiaoxin888888的专栏 2758

STM32与小米CyberGear微电机的CAN通信协议深度解析

本文深度解析STM32与小米CyberGear微电机的CAN通信协议,涵盖硬件连接、CAN总线配置、通信协议解析及多电机协同控制。重点介绍了基于STM32的电机控制实践,包括运动模式、速度与位置模式设置,以及数据反馈与故障诊断,为机器人及自动化设备开发提供实用指南。

www00的博客 374

flash as 与js通信

刚开始学习flash as3编程,一些学习笔记也丢上来吧,现在还都是些初级的话题~Flash已经提供了ExternalInterface接口与JavaScript通信,ExternalInterface有两个方法,call和addCallback,call的作用是让Flash调用js里的方法,addCallback是用来注册flash函数让js调用。下面是官方文档对call和addCallback

webnoties的专栏 2058

钉钉开发(三)——Java推送钉钉待办任务

之前一篇博文中,讲解了如何推送钉钉群消息,感兴趣的可以点击查看。 钉钉开发(一)——Java给钉钉群推送消息

Monten_Cristo的博客 6420

zemax光线光扇图

通过入瞳某一坐标(PX,PY)的光线在像面上有唯一的位置(EX,EY),以EX,EY为纵坐标,以PX,PY为横坐标,分别建立坐标系,把通过入瞳的光线都在坐标系里描点就得到了光扇图。对于视场内任意一点,取其子午面内的光线,以光线在光阑面上的透射点坐标为横坐标,同时以该光线在像面上的坐标为纵坐标,描出所有点,构成的图形即为子午面光扇图。在焦点位置,曲线的斜率为0,也就是说,不管入射时的横坐标(光阑面上的位置)是多少,离轴多远,都将汇聚在焦点处。此时,子午面和弧矢面有不同的分布,两条曲线不重合。

fendoudecheng的博客 8121

AS与JS的相互调用

一.在AS中调用JS 在FLEX中可以直接用ExternalInterface.call("sayHelloWorld"); 对JavaScript函数进行调用,sayHelloWorld为要调用的JS函数名 // JavaScript function sa

yaonai2003的专栏 9658

STM32+ESP8266接入OneNet的MQTT嵌入式实现

MQTT是一种轻量级发布/订阅模式的消息传输协议,广泛应用于资源受限的物联网终端设备通信。其基于TCP/IP栈构建,具备低带宽占用、小代码体积和高可靠性等技术优势,特别适合STM32等MCU与Wi-Fi模组协同工作的边缘节点场景。在实际工程中,需结合AT指令集控制ESP8266完成Wi-Fi连接、TCP建链及MQTT会话管理,并通过环形缓冲区、空闲中断检测等机制保障UART异步通信稳定性。本文围绕STM32F103与ESP8266硬件协同、OneNet平台对接、JSON消息解析与OLED状态反馈等关键环节,

yhn456789的博客 1044

AS3与JS交互

function StorePage(){d=document;t=d.selection?(d.selection.type!=None?d.selection.createRange().text:):(d.getSelection?d.getSelection():);void(keyit=window.open(http://www.365key.com/storeit.

1986

大疆Livox Mid-70雷达的使用

一、前期准备 (一)、使用Livox Viewer测试雷达 1、设置静态IP sudo ifconfig enx081f7152092a 192.168.1.50 查看IP是否设置成功 lacyexsale@lacyexsale-KLV-WX9:~$ ifconfig enx081f7152092a Link encap:以太网 硬件地址 08:1f:71:52:09:2a inet 地址:192.168.1.50 广播:192.168.1.255 掩码:255.255.25

LacyExsale的博客 1万+

本地部署AI应用:基于Google Gemini的banana-prompt快速上手指南

AI应用开发的核心在于将大模型能力集成到实际场景中,其原理是通过API调用将用户输入转化为模型可理解的指令,再由模型生成响应。这一技术价值在于降低AI应用开发门槛,实现数据本地化处理与隐私保护。在工程实践中,开发者常面临环境配置复杂、API集成繁琐等挑战。本文聚焦于使用banana-prompt工具包,通过TypeScript技术栈和npm包管理,快速在Windows本地部署基于Google Gemini API的AI应用。该方案特别适用于ai-prompts提示词工程和content-creation内容

weixin_27188815的博客 323

[原]as3 flash web 应用 (5)js与flash的交互

2010年06月17日 星期四 19:21 由于某度过于恶心等众所周知的原因,搬离写了5年的渣度空间,准备把技术性的文章定在CSDN了。这些都是文章备份。勿怪。。 (鉴于最近有些抓取机器和抄袭者,把标题的【原】字都复制,我不得不声明:本文为 yukon12345原创,转载请注

步满生错的专栏 3312

uniapp - 强力解决 swiper 轮播图内嵌套视频导致滑动不流畅卡顿问题,轮播滑块视图容器里既有图片也有视频video组件共同存在出现滑动切换特别卡,轮播组件包裹视频播放器加载慢及层级过高解决

uni-app,h5移动端网页,微信小程序,支付宝小程序,Android安卓,苹果ios,app,nvue,swiper,轮播图,轮播图嵌套视频,卡顿,加载慢,左右滑动不流畅,很卡,滑动过快就会卡住,uniapp使用swiper组件里嵌套视频与图片如何解决卡顿问题,详细解决教程,swiper里有视频video,播放器,视频+图片轮播,层级过高及卡顿问题,没等看完视频就自动切换了,报错,无法加载播放,uniapp的App安卓苹果端,video老是加载,APP端video组件播放视频卡顿,抖音,快手,上下滑动视

🏆 前端领域优质创作者 1万+

JS调用Flash和Flash调用JS

首先下载swfobject.js(http://code.google.com/p/swfobject/downloads/list)可以使用FlashDevelop编译as文件(注:编译时选择Release,不要选择Debug,因为Debug会把一些没用的文件编译进swf文件) as3 code:package { import flash.display.Sprite; imp

D的专栏 3605

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

javascript调用FLASH中的方法

JAVASCRIPT 与 AS 的通讯

peacelock的专栏 819

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

javascript和Flash ActionScript的交互(AS3)

 原文地址:http://www.cnblogs.com/webabcd/archive/2009/11/05/1596687.html 介绍 演示使用 Flash ActionScript 3.0 获取配置参数,页面参数,以及 js 与 as 间的交互 参数获取 - 通过 Application.application.stage.loaderInfo.parameters[p

adam2002的专栏 1257

[原]flash研究(三)——Falsh与JavaScript交互

一、getURL方法 在flash中可以用getURL方法来调用JS中的函数。 例: GetURL_btn.onRelease=function(){ getURL("javascript:window.showModalDialog(location.href,'','dialogWidth:562px;dialogHeight:468px;status:no;r...

weixin_33675507的博客 319

C#中JS和Flash中AS 3.0通信交互

工作上用到C#和Flash通信交互,C#用到JS类库,Flash用到AS3.0类库。根据实现过程进行一下总结: 首先引用swfobject.js类(下载链接:https://files.cnblogs.com/files/wxylovejx/swfobject.zip),进行加载Flash。 方法如下: ------------------------用swfobject.js加载flash...

weixin_34129145的博客 169

flash as3调用js函数新写法

转自:http://www.6dn.cn/blog/article.asp?id=151 flash as3调用js函数,可以这样写 var alert:XML = <script> <![CDATA[ function ($str) { alert($str); ...

weixin_30679823的博客 187

AS3与JS通信

一直没去深入研究下AS3与JS的交互开发也就是SWF在html中的通信,最近出于项目要求被迫投入了,也在这里做个汇总 一:HTML中最快速的传值方式 在HTML中插SWF时,可以跟个参数,比如: files/home.swf?id="21" 在AS3里可以这样去接收 AS3代码 var id:String=stage.loaderInfo.parameters["id"];

林中白狼 1248

2010年10月13号---as与js通信之as与js方法调用示例

as与js通信方法,两者方法互相调用: 上代码 as2.0 : import flash.external.ExternalInterface; _root.btn.onPress = function() { ExternalInterface.call("callServer"); } ExternalInterface.addCallback("JSCallAS",...

iteye_11390的博客 115

AS3与javascript交互

又改行了哈,战线越铺越长了,希望能静下来把战壕挖深点。       在AS2中,获取外部传递给flash的变量只需通过 _root.value即可访问到,同时访问外部只需通过getURL('link')来访问外部链接和JS代码。       然后是AS3。     获取外部变量: function getParameter(){ var param:Object = root.loaderIn...

艺术的以太 iPhone Mac Cocoa Ruby Rails 146

在js中调用flash方法

为什么80%的码农都做不了架构师?>>> ...

weixin_34221775的博客 187

JavaScript与ActionScript通讯例子

// --> // -->My JSP 'index.jsp' starting page

foart的专栏 2064
上一篇: trimpath 前端模板引擎
下一篇: iframe的document.domain问题
ibuhappy
博客等级 码龄17年 0粉丝 45原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值