views:

18

answers:

1

I have created a simple flash object to redirect a browser to a different webpage using "navigatetoURL" while getting the URL from externalinterface calls to the javascript that the page doing the embedding of the flash file has.

I am able to build everything just fine and the html page I created (using swfobject.embedSWF to embed the flash file) runs fine and redirects the browser. However when I move the files that are needed for everything to function (the .swf file, swfobject.js, and the html file that embeds the flash object) the webpage does not redirect anymore. Just a blank space, which seems to be the flash object, is displayed and nothing is redirected.

Is there any compile option in Flashdevelop that I'm missing to prevent correct this?

Here is the actionscript 3 code:

package 
{
 import flash.display.Sprite;
 import flash.events.Event;
 import flash.net.navigateToURL;
 import flash.net.URLRequest;
 import flash.net.URLVariables;
 import flash.external.ExternalInterface;

public class FlashTest extends Sprite
{
 public function FlashTest()
 {
    var url:String = ExternalInterface.call("GetURL");
    var hash:String = ExternalInterface.call("GetHash");
    var new_url:String = url + hash;
    var request:URLRequest = new URLRequest(new_url);
    navigateToURL(request, "_self");

 }
}
}

The HTML code:

<html>
<head>

<script src='js/swfobject.js' type='text/javascript'></script>
<script type='text/javascript'>
swfobject.embedSWF('Flashtest.swf', 'altContent', '100%', '100%', '10.0.0');
function GetURL()
{
   return 'http://www.cnn.com';
}

function GetHash()
{
  return '?hash=2398asb9s8234';
}

</script>
</head>
<body>
<div id='altContent'>
<h1>Flash_test</h1>
<p>Alternative content</p>
<p><a href='http://www.adobe.com/go/getflashplayer'&gt;&lt;img 
src='http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif' 
alt='Get Adobe Flash player' /></a></p>
</div>
</body>
</html>
A: 

Actually, I've been in trouble with swf's being started before they are added to the HTML DOM and/or before the DOM is ready. Have a look at Adobes own article on ExternalInterface.call and javascript isReady. I would also have a look at the allowScriptAccess parameter:

<script type="text/javascript">
   var so = new SWFObject("movie.swf", "mymovie", "400", "200", "8", "#336699");
   so.addVariable("allowScriptAccess", "always");
   so.write("flashcontent");
</script>
Aspelund