0

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!

jonathanasdf
  • 2,844
  • 2
  • 23
  • 26
Jesse
  • 10,370
  • 10
  • 62
  • 81
  • couldn't it be, that in time of calling `test(t)` it isn't defined? – Adam Kiss Apr 29 '10 at 09:46
  • Well, test(t) won't be called until the flash is loaded, as the flash_ready() function is called from the flash itself. Not sure if that makes sense, but here's the flow: UI instantiated -> constructor (UI) -> flash_ready() called -> test() called So flash, in essence, calls the test function via javascript, so test must be defined. Yeah? – Jesse Apr 29 '10 at 10:03
  • Does it do this in all browsers? I sometimes get glitches in IE which I have to iron out. – Danyal Aytekin Apr 29 '10 at 14:08
  • I've only tested in webkit & mozilla browsers, but it gives errors in GC, Safari, & Camino. – Jesse Apr 29 '10 at 16:04
  • Is the HTML element ID really "/chainmaille/includes/media/flash/upload_image"? SWFObject's second parameter is the ID of the HTML element in which you plan to embed your SWF. It's very unusual to have an ID that looks like a file path... – pipwerks Oct 27 '11 at 06:36

5 Answers5

1

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
  • 12,458
  • 3
  • 39
  • 44
1

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
  • 10,370
  • 10
  • 62
  • 81
1

Just spent 5 hours fighting with this. It was all really frustrating. In my case the solution was very very simple and I would have never guessed it. So first of for all of you who have never seen the flash player debugger running on files inside your browser finding this link that walks you through the setup has resulted in a somewhat magical experience :) Now to my ExternalInterface discovery: There was a sandbox violation inside the same domain. This meant that flash cannot access www.yourdomain.com from yourdomain.com. The weird thing of course is that you are not explicitly calling the domain with ExternalInterface. Anyhow, the solution was very simple: add this to my .htaccess file and that was it!

# Redirect non-www to www 
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.youtdomain.com/$1 [R=301,L] 

Hope this helps someone

Cdelconde
  • 11
  • 1
0

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);
Aaron
  • 4,634
  • 1
  • 27
  • 43
  • 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 Apr 29 '10 at 18:22
0

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
  • 803
  • 1
  • 7
  • 14