dtpf76658 2011-06-03 05:38
浏览 38
已采纳

使用flashvars将php变量发送到flash

I have a flash player embedded on page page.php?user=john using swfobject. The player calls the xml file content.php to get the results. I'm trying to get the user name from the url id. and fetch results based on that. I can get the username on page.php by doing $_GET['user'], but how can i pass that to content.php. Having read allot of articles online, i did the following,

I'm embedding the flash on page.php using swfobject like this

<script type="text/javascript">
    var flashvars = {user:"<?php $_GET[user] ?>"};
    var so = new SWFObject("<?php echo $index->CFG['site']['url'];?>preview2.swf", "sotester", "1000", "400", "8", "#000000", flashvars);
    so.addParam("allowFullScreen", "true");
    so.addParam("scale", "noscale");
    so.addParam("menu", "false");
    so.write("flashcontent");
</script> 

In my AS2 file end of the file looks like

var paramList:Object = this.root.loaderInfo.parameters;
trace(paramList["user"])
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("contentp.php?user=" + user);

So basically, i'm trying to pass $_GET['user'] from page.php to my swf file which calls content.php. Then swf would pass that value to content.php. I believe i provided you with all the information needed. Any help would be appreciated.

PS: right now as i have it, looking at console, i see Request URL:http://www.domain.com/content.php?user=undefined. So it's coming as undefined.

  • 写回答

2条回答 默认 最新

  • dqx13503925528 2011-06-03 17:35
    关注

    Embed like so with SWFObject v2.2

    <html>
      <head>
      <title></title>
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
      <script type="text/javascript" src="swfobject.js"></script>
      <script type="text/javascript">
        function loaded( ){
          var flashvars = { };
              flashvars.user = "<?php $_GET[user] ?>";
    
          var params = {};
              params.menu = "false";
              params.quality = "high";
              params.bgcolor = "#869ca7";
              params.allowFullScreen = "true";
              params.scale = "noscale";
    
          var attributes = {};
              attributes.id = "myFlashObject";
              attributes.name = "myFlashObject";
              attributes.align = "middle";
              attributes.allowFullScreen = "true";
              attributes.scale = "noscale";
    
          var tmp = "expressInstall.swf";
          var version = "8.0.0";
          var width = "1000";
          var height = "400";
          var container = "sotester"
    
          // verify the URL is correct
          var flashObj = "<?php echo $index->CFG['site']['url'];?>preview2.swf";
    
          swfobject.embedSWF(flashObj, container, width, height, version, tmp, flashvars, params, attributes);
    
        }
      </script>
      </head>
    <body onLoad="loaded()">
      <div id="sotester">Loading Content... put alt. content here</div>
    </body>
    </html>
    
    
    
    // in actionscript 3
    var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
    var user: String = String( paramObj[user] );
    trace( user );
    

    [EDIT]

    // in actionscript 2
    // _level0 will have the global flashvar on it
    // trace(user);
    

    REFERENCE

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真