作者ben0209 (邦邦)
看板Flash
标题Re: [问题] swf 嵌入 jsp 中 传参数问题
时间Thu Aug 25 18:58:05 2011
先不管 JSP / ASP / PHP 的问题,总之最後都是 HTML,请先确认 HTML 应如下:
<!-- saved from url=(0014)about:internet -->
<html lang="en">
<!--
Smart developers always View Source.
This application was built using Adobe Flex, an open source framework
for building rich Internet applications that get delivered via the
Flash Player or to desktops via Adobe AIR.
Learn more about Flex at
http://flex.org
// -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="AC_OETags.js" language="javascript"></script>
<style>
body { margin: 0px; overflow:hidden }
</style>
</head>
<body scroll='no'>
<script language="JavaScript" type="text/javascript">
<!--
AC_FL_RunContent(
"src", "TestHtmlParam",
"flashvars", "mainView=123",
"width", "100%",
"height", "100%",
"align", "middle",
"id", "TestHtmlParam",
"quality", "high",
"bgcolor", "#869ca7",
"name", "TestHtmlParam",
"allowScriptAccess","sameDomain",
"type", "application/x-shockwave-flash",
"pluginspage", "
http://www.adobe.com/go/getflashplayer"
);
// -->
</script>
</body>
</html>
重点在於 flashvars 那边的 mainView 有值~
第二步骤,因为要取得 html 带进来的 param,必须透过 stage,
所以你应该是在 ADDED_TO_STAGE 事件之後才能取得,如下:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
layout="vertical" minWidth="955" minHeight="600"
addedToStage="application1_addedToStageHandler(event)">
<mx:Script>
<![CDATA[
import mx.events.FlexEvent;
protected function application1_addedToStageHandler(event:Event):void
{
trace("mainView=" + stage.loaderInfo.parameters["mainView"]);
}
]]>
</mx:Script>
</mx:Application>
执行输出:
[SWF] E:\works_test\Test\bin-debug\TestHtmlParam.swf - 636,687 bytes after
decompression
mainView=123
※ 引述《cashlalala (快来跟我做朋友)》之铭言:
: 各位大大好
: 我在一个jsp中嵌入一个 swf
: 而jsp会有一些http request 传进来的参数要给swf
: 我google一下网路上的写法後 在jsp中写入下面这一段
: <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
: codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
: width="550" height="400" id="as3flashvars" align="middle">
: <param name="allowScriptAccess" value="sameDomain" />
: <param name="allowFullScreen" value="false" />
: <param name="movie"
: value="http://localhost:8080/IncludeVsForward/Flex/EPLMInCaringorm.swf?mainView=<%=request.getParameter("mainView")%>&user=<%=request.getParameter("user")%>" />
: <param name="quality" value="high" />
: <param name="bgcolor" value="#ffffff" />
: <param name="flashVars"
: value="mainView=<%=request.getParameter("mainView")%>&user=<%=request.getParameter("user")%>">
: <embed
: src="http://localhost:8080/IncludeVsForward/Flex/EPLMInCaringorm.swf?mainView=<%=request.getParameter("mainView")%>&user=<%=request.getParameter("user")%>"
: quality="high" bgcolor="#ffffff" width="550" height="400"
: name="as3flashvars" align="middle" allowScriptAccess="sameDomain"
: allowFullScreen="false" type="application/x-shockwave-flash"
: pluginspage="http://www.macromedia.com/go/getflashplayer"
: flashVars=
: "mainView=<%=request.getParameter("mainView")%>&user=<%=request.getParameter("user")%>" />
: </object>
: 不管是直接加在网址後面, 或者是透过flashvars来传递我都使用了
: 然後在flex中加入
: protected function application1_creationCompleteHandler(event:FlexEvent):void
: {
: // TODO Auto-generated method stub
: var aa : String = root.loaderInfo.parameters.mainView;
: Alert.show(aa);
: var mainViewStackEvent :MainViewStackEvent = new MainViewStackEvent(MainViewStackEvent.EVENTNAME,mainViewVO);
: mainViewStackEvent.dispatch();
: }
: 上网查不外乎都是这样写, 但是很怪的是root怎麽样都是null,
: 请问有大大有相关的经验要如何解决吗?
: 我爬过文似乎没有跟我很类似的
: 请各位大大不吝指教 谢谢!!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 122.147.239.66