Flex学习笔记[1]:AS与JS的相互通信

原文链接:http://www.cnblogs.com/yaoyaminaco/archive/2011/08/25/2153484.html

环境:Flex Builder 3(AS3.0)

测试:点击客户端button,底层背景左下移动200px,flex绘制的三角的填充色由0x000000(黑)变0x00ffff(淡蓝)色

注意事项:1.IIS必须部署  2.通信前需检测是否ExternalInterface.available

一 MXML文件:FlexTest3.mxml

 1 <?xml version="1.0" encoding="utf-8"?>
2 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="Init()" backgroundColor="red" backgroundAlpha="0">
3 <mx:Script>
4 <![CDATA[
5 import mx.core.UIComponent;
6 import flash.external.ExternalInterface;
7
8 protected var itvAnim:Number;
9 protected var itvTime:Number=1000;
10 protected var ucAngle:UIComponent=new UIComponent();
11 protected var spAngle:Sprite=new Sprite();
12 protected var RGB:Number=0x000000;
13
14
15 protected function Init():void
16 {
17 cvsAngleContainer.addChild(ucAngle);
18 ucAngle.addChild(spAngle);
19 //AStoJS
20 if(ExternalInterface.available)
21 ExternalInterface.addCallback("myTestAStoJS",AStoJS);
22 InitTimer();
23 }
24
25 protected function InitTimer():void
26 {
27 itvAnim=setInterval(Anim,itvTime);
28 }
29
30 protected function Anim():void
31 {
32 if(ExternalInterface.available)
33 {
34 //JStoAS
35 var fillColor:String=ExternalInterface.call("getColor");
36 if(fillColor!=null&&fillColor!="")
37 RGB=parseInt(fillColor,16);
38 }
39 spAngle.graphics.clear();
40
41 spAngle.graphics.lineStyle(1,0,100);
42
43 for(var i:int=0;i<3000;i++)
44 {
45 var newX:int=500-Math.round(Math.random()*1000);
46 var newY:int=500-Math.round(Math.random()*1000);
47
48 spAngle.graphics.beginFill(RGB);
49 spAngle.graphics.moveTo(500+newX,500+newY);
50 spAngle.graphics.lineTo(510+newX,500+newY);
51 spAngle.graphics.lineTo(505+newX,520+newY);
52 spAngle.graphics.lineTo(500+newX,500+newY);
53 spAngle.graphics.endFill();
54 }
55 }
56
57 public function AStoJS():int
58 {
59 return 99;
60 }
61 ]]>
62 </mx:Script>
63 <mx:Canvas id="cvsAngleContainer" verticalCenter="0"
64 horizontalCenter="0" width="1000" height="1000"
65 backgroundColor="red" backgroundAlpha="0" >
66
67 </mx:Canvas>
68 </mx:Application>

 

二 Html静态页面

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="history/history.css" />
<title></title>
<script src="js/jquery-1.4.2.min.js" language="javascript"></script>
<script src="js/jquery.easydrag.handler.js" language="javascript"></script>
<script src="AC_OETags.js" language="javascript"></script>
<script src="history/history.js" language="javascript"></script>
<style>
body { margin: 0px; overflow:hidden }
</style>
<script language="JavaScript" type="text/javascript">
var direction="left";
var angleColor="0x00ffff";	//蓝色三角
var isChange=false;

$(document).ready(function () {
	//实现拖动
	$('#container').easydrag();
	$('#container').css("overflow","hidden");
	//绘制底图
	for(var r=0;r<5;r++)
	{
		for(var c=0;c<5;c++)
		{
			var divTmp=document.createElement("div");
			divTmp.style.width="200px";
			divTmp.style.height="200px";
			divTmp.style.position="absolute";
			divTmp.style.zIndex="-100";
			divTmp.style.background="url(map/2560000/0_0/2560000__0_0_"+r+"_"+c+".png) no-repeat";
			divTmp.style.top=c*200+"px";
			divTmp.style.left=r*200+"px";
			divTmp.id="map_"+r+"_"+c;
			$('#container').append(divTmp);
		}
	}
	
	var btnTest=document.createElement("input");
	btnTest.type="button";
	btnTest.id="btnTest";
	btnTest.style.width="80px";
	btnTest.style.height="20px";
	btnTest.style.position="absolute";
	btnTest.style.top=490;
	btnTest.style.left=460;
	btnTest.value="我要交互!";
	$(btnTest).click(btnJS).click(callFlexAS).click(function(){isChange=true;});
	$('#container').append(btnTest);
	
	//var str=document.getElementsByTagName('object');
	//alert(str[0].id);
});

function btnJS()
{
	var arrayDiv=document.getElementsByTagName('div');
	if(direction=="left")
	{
		for(var i=1;i<arrayDiv.length;i++)
		{
			var oldTop=arrayDiv[i].style.top;
			var oldLeft=arrayDiv[i].style.left;
			
			$(arrayDiv[i]).css("top",parseInt((parseInt(oldTop)+200)+"px")).css("left",parseInt((parseInt(oldLeft)-200)+"px"));
			direction="right";
		}
	}
	else
	{
		for(var i=1;i<arrayDiv.length;i++)
		{
			var oldTop=arrayDiv[i].style.top;
			var oldLeft=arrayDiv[i].style.left;
			
			$(arrayDiv[i]).css("top",parseInt((parseInt(oldTop)-200)+"px")).css("left",parseInt((parseInt(oldLeft)+200)+"px"));
			direction="left";
		}
	}
}
function getColor()	  //as调用js
{
	if(isChange==true)
	{
		angleColor="0x00ffff";
		return angleColor;
	}
	else
	{
		return "0x000000";
	}
}
function callFlexAS()	//js调用as
{
	var x=FlexTest3.myTestAStoJS();
	alert(x);
	return;
}

<!--
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 124;
// -----------------------------------------------------------------------------
// -->
</script>
</head>
<body>
<div style="width:1000px;height:1000px;position:relative;" id="container">
<script language="JavaScript" type="text/javascript">
<!--
// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);

// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

if ( hasProductInstall && !hasRequestedVersion ) {
	// DO NOT MODIFY THE FOLLOWING FOUR LINES
	// Location visited after installation is complete if installation is required
	var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
	var MMredirectURL = window.location;
    document.title = document.title.slice(0, 47) + " - Flash Player Installation";
    var MMdoctitle = document.title;

	AC_FL_RunContent(
		"src", "playerProductInstall",
		"FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
		"width", "1000px",
		"height", "1000px",
		"align", "middle",
		"id", "FlexTest3",
		"quality", "high",
		"bgcolor", "#ff0000",
		"wmode","transparent",
		"name", "FlexTest3",
		"allowScriptAccess","sameDomain",
		"type", "application/x-shockwave-flash",
		"pluginspage", "http://www.adobe.com/go/getflashplayer"
	);
} else if (hasRequestedVersion) {
	// if we've detected an acceptable version
	// embed the Flash Content SWF when all tests are passed
	AC_FL_RunContent(
			"src", "FlexTest3",
			"width", "1000px",
			"height", "1000px",
			"align", "middle",
			"id", "FlexTest3",
			"quality", "high",
			"bgcolor", "#ff0000",
			"wmode","transparent",
			"name", "FlexTest3",
			"allowScriptAccess","sameDomain",
			"type", "application/x-shockwave-flash",
			"pluginspage", "http://www.adobe.com/go/getflashplayer"
	);
  } else {  // flash is too old or we can't detect the plugin
    var alternateContent = 'Alternate HTML content should be placed here. '
  	+ 'This content requires the Adobe Flash Player. '
   	+ '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
    document.write(alternateContent);  // insert non-flash content
  }
// -->
</script>  	
</div>
<noscript>
	<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
			id="FlexTest3" width="100%" height="100%"
			codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
			<param name="movie" value="FlexTest3.swf" />
			<param name="quality" value="high" />
			<param name="bgcolor" value="#ff0000" />
			<param name="wmode" value="transparent"/>
			<param name="allowScriptAccess" value="sameDomain" />
			<embed src="FlexTest3.swf" quality="high" bgcolor="#ff0000"
				width="100%" height="100%" name="FlexTest3" align="middle"
				play="true"
				loop="false"
				quality="high"
				allowScriptAccess="sameDomain"
				type="application/x-shockwave-flash"
				pluginspage="http://www.adobe.com/go/getflashplayer" wmode="transparent">
			</embed>
	</object>
</noscript>
</body>
</html>

转载于:https://www.cnblogs.com/yaoyaminaco/archive/2011/08/25/2153484.html

原文地址:https://blog.csdn.net/weixin_30675247/article/details/99420909

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


一:display:flex布局display:flex是一种布局方式。它即可以应用于容器中,也可以应用于行内元素。是W3C提出的一种新的方案,可以简便、完整、响应式地实现各种页面布局。目前,它已经得到了所有浏览器的支持。Flex是FlexibleBox的缩写,意为"弹性布局",用来为盒状模型提供最大的灵
1. flex设置元素垂直居中对齐在之前的一篇文章中记载过如何垂直居中对齐,方法有很多,但是在学习了flex布局之后,垂直居中更加容易实现HTML代码:1<divclass="demo">2<divclass="inner">3<p>这是一个测试这是一个测试这是一个测试这是一个测试这是一个测试</p>4</div
移动端开发知识点pc端软件和移动端apppc端软件是什么,有哪些应用。常见的例子,比如360杀毒,photoShop,VisualStudioCode等等移动端app是什么,有哪些应用。常见的例子,比如手机微信,手机qq,手机浏览器,美颜相机等等PC端与移动端的区别第一:PC考虑的是浏览器的兼容性,移动端考
最近挺忙的,准备考试,还有其他的事,没时间研究东西,快周末了,难得学点东西,grid是之前看到的,很好奇,讲的二维的布局,看起来很方便,应该很适合移动端布局,所以今天抽时间学一学,这个当是笔记了。参考的是阮老师的博客。阮一峰:CSSGrid网格布局教程http://www.ruanyifeng.com/blog/2019/03/g
display:flex;把容器设置为弹性盒模型(设置为弹性盒模型之后,浮动,定位将不会有效果)给父元素设置的属性:(1)display:flex---把容器设置为弹性盒模型。(2)flex-direction---设置弹性盒模型主轴方向默认情况下主
我在网页上运行了一个Flex应用程序,我想使用Command←组合键在应用程序中触发某些操作.这在大多数浏览器上都很好,但在Safari上,浏览器拦截此键盘事件并导致浏览器“返回”事件.有没有办法,通过Flex或通过页面上的其他地方的JavaScript,我可以告诉Safari不要这样做?解决方法:简短的
flex布局,flex-item1<template>2<viewclass="container">3<viewclass="greentxt">4A5</view>6<viewclass="redtxt">7B8<
我应该设计一个大型多点触控屏幕的应用程序.从大到大,我的意思是新闻广播员(大约55英寸及以上).该应用程序是一个交互式地图.我的问题是:开发应用程序的技术.我的第一个想法是在AdobeFlex中制作,但是HTML5也是如此……必须有一些非常棒的Java库用于触摸交互,但是在Windows平台上
<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><metahttp-equiv="X-UA-Compatible&quo
【1】需求:  【2】解决方案:最近遇到布局上要求item两端对齐,且最后一行在列不满的情况下要求左对齐,使用flex的justify-content:space-between;实现时发现最后一行不能左对齐,而是两端对齐方式。 不是项目上想要的效果#网上查了一些资料,有两种方法可以实现效果:**1.
我有一个java套接字服务器,它在连接时将Animal对象发送到Flash客户端.对象发送方式如下:Amf3Outputamf3Output=newAmf3Output(SerializationContext.getSerializationContext());amf3Output.setOutputStream(userSocket.getOutputStream());amf3Output.writeObject(animal)
我正在开发一个Flex3.4应用程序,它通过最新版本的BlazeDS与JBoss-4.2.2服务器上运行的JavaEE后端进行交互.当我在Tomcat上从FlashBuilder4beta2运行Flex应用程序时,一切都很好,Flex应用程序能够进行所需的远程调用.但我的生产环境是在JBoss上,当我将应用程序移动到JBoss时(更
我有一个非常大的问题.我使用Flex3/Tomcat/BlazeDS/Spring编写了一个大型应用程序,在本地开发时运行良好,当我部署到公共开发环境时很好,但是当部署到我们的测试环境时经常失败.当远程处理请求花费大量时间(超过20秒)时,故障似乎最常发生.在我的开发服务器上,错误发生,但仅
弹性和布局display:flex在ie6,ie7不兼容状态,一般在pc用的比较少,在手机端所有的浏览器都是支持的控制子元素在父元素里面的位置关系display:flex是给父元素加的文档流是按照主轴排列,只要父元素加了flex,那么里面的子元素全部可以直接添加宽高主轴的方向
FLEX2.0源码分析(一)https://www.jianshu.com/p/8bc4c5f4b19fFLEX源码分析二(网络监测swizzle)https://www.jianshu.com/p/ffb95f2cbda6FLEX源码分析三(网络监测记录FLEXNetworkRecorder)https://www.jianshu.com/p/66267dc922c5FLEX源码分析四(Systemlog)https://www.jianshu.
1<!DOCTYPEhtml>2<htmllang="en">3<head>4<metacharset="UTF-8">5<title><itle>6<style>7*{8margin:0;9padding:0;10
<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><metahttp-equiv="X-UA-Compatible&qu
flex:将对象作为弹性伸缩盒显示inline-flex:将对象作为内联块级弹性伸缩盒显示两者都是使子元素们弹性布局,但是如果是flex,父元素的尺寸不由子元素尺寸动态调整,不设置时默认是100%,而inline-flex则会使父元素尺寸跟随子元素们的尺寸动态调整。
<html><head><metacharset="utf-8"><metaname="viewport"content="width=device-width"><title>test<itle><stylemedia="screen">.tab-head{list-style-type:no
有没有办法使用邮政编码找到径向距离?我的任务是搜索居住在指定距离内的所有用户.我知道用户的zipcodes.例如,距离当前位置25英里的用户.我有其他搜索类别,我正在使用mysql查询.我无法解决距离问题.我的后端是在PHP中Flex的前端和前端.对我来说最好的选择就是www.zip-codes.com