0

I see there's questions on this already, however after looking through all those and matching my code I can't get the right effect. I'm trying to call a simple AS3 method from JS.

As below:

AS3:

    private function InitialiseCallbacks():void
{
    ExternalInterface.call("FlashReady");
    ExternalInterface.addCallback("ReturnMall", ReturnToMall);
}

    public function ReturnToMall():void
    {
        trace("ReturnMall: WORKED"); // Not being called

        this.mall_map.visible = false;
    }

Javascript:

                        function FlashReady()
                    {
                        swf = document.getElementById("CaviaGame");
                        console.log(swf);
                    }

        function ShoppingMallClicked()
        {
                        $(".shoppingmallbtn").effect("shake", { times:3 }, 5);

                        console.log(swf);
                        swf.ReturnMall();
        }
        <div align="center" id="flashContent">
        <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="760" height="760" name="CaviaGame" id="CaviaGame" align="top">
            <param name="movie" value="CaviaGame.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 value="true" name="swLiveConnect" />
            <param name="salign" value="" />
            <param name="allowScriptAccess" value="always" />
            <!--[if !IE]>-->
            <object type="application/x-shockwave-flash" data="CaviaGame.swf" width="760" height="760">
                <param name="movie" value="CaviaGame.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 value="true" name="swLiveConnect" />
                <param name="salign" value="" />
                <param name="allowScriptAccess" value="always" />
            <!--<![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>

Javascript Console:

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="760" height="760" name="CaviaGame" id="CaviaGame" align="top">
Uncaught TypeError: undefined is not a function

From what I can see it recognises the reference to my swf, but doesn't recognise that there's a function in it, or is failing to call it. I've done a callback from AS3 to Javascript, which calls successfully before retrieving the reference to the swf. However upon calling the function it still doesn't work.

I allowed access in the swfObject in html, I also tried Security.allowDomain() in the AS3 as well to no avail.

I haven't created this entire project myself, however I see this code in the project:

        public function initializeMapViewerModule()
    {

            global.GameMode = "LoadingMapViewer";

            // Initiate MapViewer Load
            var queue:LoaderMax = new LoaderMax({name:"MapViewerQueue", onComplete:onLoadMapViewerModule});         
            queue.append( new SWFLoader("CaviaMapViewer.swf", {name:"CaviaMapViewer", estimatedBytes:5000, x:0, autoPlay:false}) );         
            queue.load();               

    } // END - initializeMapViewerModule

Could this possibly be another swf to the referenced one, which contains the code? Or would it be all being called from the swfObject put in from the html? If it's another how would I reference it?

Any advice appreciated as I've really searched heavy for this and am stumped.

Thanks!

Nigel
  • 15
  • 6
  • So is the AS3 code with the ExternalInterface stuff in `CaviaGame.swf` or `CaviaMapViewer.swf`? – BadFeelingAboutThis Jan 09 '15 at 20:26
  • Well it's in a class called 'CaviaMapViewer', inside the 'com' folder, which both CaviaGame AND CaviaMapViewer link to. Not only that, but I set up the code for this in both CaviaGame.as AND CaviaMapViewer.as on separate occasions to try and debug the problem, neither worked any differently... – Nigel Jan 09 '15 at 22:36
  • I think you should be using swfobject to place your swf (standard). Here's a post about using swfobject and js that should work: http://stackoverflow.com/questions/7657842/how-to-call-flash-actionscript-callback-method-from-javascript – moot Jan 10 '15 at 07:22
  • Thanks for the reply Moot. I could be totally wrong, but from what I'm seeing on google (http://learnswfobject.com/the-basics/index.html), I'm already using swfObject with static publishing. I can see you can dynamically publish the Flash, but I'm not sure how that'd change the scenario? I saw this method of making it and recognise the formula. Make sure the swf in loaded, then create a reference to the swf, create a addCallback, then using that reference call the method in Flash by naming the string first parameter from the addCallback.. It still doesn't work with my project :O – Nigel Jan 10 '15 at 13:56
  • Hi guys I found the answer to my problem in the end. It's a bit of a confusing one. I was referencing the wrong swf. If you look at where I place the swfObject in html, you'll notice the 'if(!IE)' section has no ID or Name. The issue is if you use the OTHER one it'll still create a correct reference to it, which can be confusing because although there is a correct reference, the swf doesn't exist. It only exists as the !IE version. Make sure to reference both versions: http://stackoverflow.com/questions/14345936/how-to-allow-javascript-to-communicate-with-flash-object-htmlobjectelement-h – Nigel Jan 12 '15 at 10:14

0 Answers0