Question

I am working on a project that is intended to track users using Local Shared Objects. The user first visits page A, which has an embedded .swf that plants a Local Shared Object. I know it works by testing it my own flash cookies.

Upon visiting page B, another embedded .swf will attempt to retrieve the flash cookie and call an AJAX function if the cookie is present. Page B is what I am having trouble with. On this webpage is embedded a .swf object, along with an AJAX function. The following code is the HTML for page B. It includes the AJAX script, along with an embedded .swf.

<!DOCTYPE html>
<html lang="en">
    <head>
        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
        <script type="text/javascript">
            function databaseAndemail(){
            $.get('http://www.mywebsite.com/databaseAndemail.php');
            }
        </script>   
    </head>
    <body>
            <object width="1" height="1">
                <param name="CheckLSO" value="http://www.mywebsite.com/CheckLSO.swf">
                <embed src="http://www.mywebsite.com/CheckLSO.swf" width="1" height="1">
                </embed>
            </object>
    </body>

The problem is not with the AJAX function, nor the PHP script, because I know that works. The problem may lie within the .swf script that is meant to check the LSO. This is the AS3 script called CheckLSO.swf:

public function Main():void 
    {
        //Check for a LSO
        var myLocalData:SharedObject = SharedObject.getLocal("myData");
        if (myLocalData.data.uname != null){ //LSO exists, so call AJAX function to update database and send email.
                if (ExternalInterface.available){
                    ExternalInterface.call("databaseAndemail");
                }               
            };

        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    } 

I'll include the AS3 script that sets the cookies here for your information (again, I've tested this one and it works):

public function Main():void 
    {
            // Create a new SharedObject
        var myLocalData:SharedObject = SharedObject.getLocal("myData");
        // Save data to the SharedObject
        myLocalData.data.uname = "ERE";
        myLocalData.flush();
        if (stage) init();
        else addEventListener(Event.ADDED_TO_STAGE, init);
    }

To sum it up, I think for some reason the Javascript function is not being called by External Interface. I know the cookie is set, I know the AJAX works, and I know the PHP script works (I haven't included the PHP, it seems like it would be outside the scope of this question). Both .swf scripts are debugged. I use FlashDevelop with Flex 4. These are really simple scripts, so I can't think of anything else that might be going wrong. Any ideas??

Was it helpful?

Solution

Might be the script access setting. On the embed, try including the param allowscriptaccess: "always". External Interface calls will fail without it.

<object width="1" height="1">
    <param name="CheckLSO" value="http://www.mywebsite.com/CheckLSO.swf">
    <param name="allowscriptaccess" value="always">
    <embed src="http://www.mywebsite.com/CheckLSO.swf" width="1" height="1"></embed>
</object>

Better yet, use swfObject 2 to embed your swf.

SwfObject

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top