views:

159

answers:

4

Hey, so I'm having a bunch of trouble getting ExternalInterface to work, which is odd, because I use it somewhat often.

I'm hoping it's something I just missed because I've been looking at it too long.

The flash_ready function is correctly returning the objectID, and as far as I can tell, everything else is in order.

Unfortunately, when I run it, I get an error (varying by browser) telling me that basically document.getElementById(<movename>).test() is not a valid method.

Here's the code:

javascript:

function flash_ready(i){
    document.getElementById(i).test('success!'); 
}

Embed Html (Generated):

<script type="text/javascript">
    swfobject.embedSWF("/chainmaille/includes/media/flash/upload_image.swf", "/chainmaille/includes/media/flash/upload_image", "500", "50", "9.0.0","expressInstall.swf", {}, {allowScriptAccess:'always', wmode:'transparent'},{id:'uploader_flash',name:'uploader_flash'});
</script>
<object type="application/x-shockwave-flash" id="uploader_flash" name="uploader_flash" data="/chainmaille/includes/media/flash/upload_image.swf" width="500" height="50"><param name="allowScriptAccess" value="always"><param name="wmode" value="transparent"></object>

AS3 :

package com.jesseditson.uploader {

  import flash.display.MovieClip;
  import flash.external.ExternalInterface;
  import flash.system.Security;

    public class UI extends MovieClip {

     // Initialization:
     public function UI() {
        Security.allowDomain('*');
        ExternalInterface.addCallback("test", test);

        var jscommand:String = "flash_ready('"+ExternalInterface.objectID+"');";
        var url:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
        navigateToURL(url, "_self");
    }

    public function test(t){
      trace(t);
    }
  }
}

Swfobject is being included via google code, and the flash embeds just fine, so that's not the problem.

I've got a very similar setup working on another server, but can't seem to get it working on this one. It's a Hostgator shared server. Could it be the server's fault? Anybody see any obvious syntax problems?

Thanks in advance!

A: 

Is flash_ready receiving the objectID that you are expecting?

Also, why use:

var jscommand:String = "flash_ready('"+ExternalInterface.objectID+"');";
var url:URLRequest = new URLRequest("javascript:" + jscommand + " void(0);");
navigateToURL(url, "_self");

When this is designed to do that:

ExternalInterface.call("flash_ready", ExternalInterface.objectID);
Tegeril
flash_ready is receiving the object I was expecting, as for using the call method, I had just added that because of my prior success with it, this code is definitely not complete, I'll move the calls over to ExternalInterface as soon as I resolve this issue. Thanks!
Jesse
A: 

Post your source (pre-generatred). When your browser says [Flash].Method is not a function, 99% of the time it means that you tried calling a function in Flash before the .swf was ready for it. I see that you tried to do that, but clearly its not working so something must be off. So post your pre-rendered source and I am sure we can find the problem.

Jason
+1  A: 

The Flash isn't actually finished constructing yet. You're calling your flash_ready callback from the constructor, and so the JS is trying to call in before the object is on the stage. Move your flash_ready call to, say, an Event.ADDED_TO_STAGE listener and it should start working.

Cory Petosky
A: 

Ok, so after further investigation, it appears that there was a problem with multiple instances of the flash object, because I was cloning it to a lightbox. I have gotten it working now.

Jesse