开发者

How to pass 2 variables to Flash?

First off, I'm using Flash CS5.5, AS3.

I'm trying to pass variables representing name and email address to a swf file. The swf takes a picture with the users webcam and sends the image to save.php for further processing. Currently I have text fields for the user to enter name and email, but I'd like to eliminate them and add the info behind the scenes. Basically this is what I'm tryi开发者_开发问答ng to accomplish:

 1.Page loads and stores name and email address in variables(index.php).
 2.I'd like to pass name and email address variables to flash to be included with
   the image the swf sends to a php file for processing (save.php)
 3.Page loads flash content(take_picture.swf) and does it's thing.

I've got this working in a similar situation using Zend AMF, where the swf gets all the info passed back from another page accessing the database. Here I have the data I need without accessing the database. I've tried many variations using FlashVars, but nothing has worked yet. One thing I seem to be missing is when I publish the fla, there is no ac_fl_runcontent in the html code Flash publishes. And there is no <embed src=... either. This div is the body of the html file Flash gives me:

 <div id="flashContent">
        <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="760" height="1000" id="take_picture" align="middle">
            <param name="movie" value="take_picture.swf" />
            <param name="quality" value="high" />
            <param name="bgcolor" value="#ffffff" />
            <param name="play" value="true" />
            <param name="loop" value="true" />
            <param name="wmode" value="window" />
            <param name="scale" value="showall" />
            <param name="menu" value="true" />
            <param name="devicefont" value="false" />
            <param name="salign" value="" />
            <param name="allowScriptAccess" value="sameDomain" />
            <!--[if !IE]>-->
            <object type="application/x-shockwave-flash" data="take_picture.swf" width="760" height="1000">
                <param name="movie" value="take_picture.swf" />
                <param name="quality" value="high" />
                <param name="bgcolor" value="#ffffff" />
                <param name="play" value="true" />
                <param name="loop" value="true" />
                <param name="wmode" value="window" />
                <param name="scale" value="showall" />
                <param name="menu" value="true" />
                <param name="devicefont" value="false" />
                <param name="salign" value="" />
                <param name="allowScriptAccess" value="sameDomain" />
            <!--<![endif]-->
                <a href="http://www.adobe.com/go/getflash">
                    <img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" />
                </a>
            <!--[if !IE]>-->
            </object>
            <!--<![endif]-->
        </object>
    </div>

I've tried <param name="FlashVars" value="first_name=<?php echo $first_name; ?>&email=<?php echo $email ?>" /> with something along the lines of this.loaderInfo.parameters.first_name and this.loaderInfo.parameters[first_name] in the actions panel along with some other things but haven't gotten it to work yet. Any help would be appreciated.

Thanks very much,

Mark

EDIT: This is my latest attempt:

 var f_name:String;
 var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
 f_name = String(paramObj[first_name]);
 first_name.text=f_name;

With this in the html:

 <param name="FlashVars" value="first_name=<?php echo $first_name; ?>"/>


Here's something simple to give you an idea:

Embed:

<object width="800" height="600">
    <param name="flashvars" value="first_name=blah&email=blah" />
    <embed src="clipping.swf?first_name=blah&email=blah" width="800" height="600" />
</object>

AS3:

var parsed:Object = root.loaderInfo.parameters;

trace(
    parsed.first_name,
    parsed.email
);


the best/easiest way to add a SWF to your html page is SWFObject.

just add the script to your file

<script type="text/javascript" src="swfobject.js"></script>

you can then add all necessary attributes/params like this:

<script type="text/javascript">
    // <![CDATA[

    var width = 800;
    var height = 600;

    var flashVersion = "9.0.115";

    var movie = "clipping.swf";

    var movieName = "flashMovie";
    var bgColor = "#ffffff";

    var express = "expressInstall.swf";

    var replaceDiv = "flashContent";

    var flashvars = {};
    flashvars.first_name = "<?php echo $first_name; ?>";
    flashvars.email = "<?php echo $email; ?>";

    var params = {};
    params.bgcolor = bgColor;
    params.menu = "false";
    params.scale = "noscale";
    params.allowFullScreen = "true";
    params.allowScriptAccess = "always";

    var attributes = {};
    attributes.id = movieName;

    swfobject.embedSWF(movie, replaceDiv, width, height, flashVersion, express, flashvars, params, attributes);


  // ]]>
</script>

i think this is not so confusing as to edit both EMBED and OBJECT tag and you only have to change an attribute once and SWFObject does the rest. definitely worth taking a look...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜