millard
millard

Reputation: 11

Javascript can't call an object inside a function

Sorry, I am new to javascript. I am trying to call an object from inside a function to allow me to get a variable from a flash file at set intervals. For some reason the object is not working inside the timer function.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>DIY Map</title>

<style>
 * { margin:0; padding:0; }
</style>

</head>
<body style="font-family:verdana;color:#999; background-image:url('bg.png'); background-repeat:no-repeat;">

<script type="text/javascript" src="js/JavaScriptFlashGateway.js"></script>
<script type="text/javascript" src="js/Exception.js"></script>
<script type="text/javascript" src="js/FlashTag.js"></script>
<script type="text/javascript" src="js/FlashSerializer.js"></script>
<script type="text/javascript" src="js/FlashProxy.js"></script>



<script type="text/javascript">
 var uid = new Date().getTime();
 var flashProxy = new FlashProxy(uid, 'js/JavaScriptFlashGateway.swf');
    var tag = new FlashTag('world.swf?data_file=data.xml, 600, 325);
    tag.setFlashvars('lcId='+uid);
    tag.write(document);


</script>

//flashProxy.call works here:
<p><a href="javascript:flashProxy.call('zoomOut');">Zoom Out</a>

<a href="javascript:flashProxy.call('refreshData','other_data.xml');">Get new data</a>

<p><a href="javascript:flashProxy.call('getZoom');">getZoom</a> | <a href="javascript:flashProxy.call('getCoords');">getCoords</a></p>



<script type="text/javascript">
// Start the refreshing process

var seconds = 3;
var zoom;
var coords;

//timer loop
function checkmap()
{
//flashProxy doesn't work here
flashProxy.call('getCoords');     
flashProxy.call('getZoom');   
alert (coords);
alert (zoom);    


setTimeout('checkmap()',seconds * 1000);
}
checkmap();



//Returns results here:
function gotCoords(n)
{
    coords = n;
}
function gotZoom(n)
{
    zoom = n;   
}
</script>

To clarify, I am trying to get the flashProxy.call('****') to work in the checkmap() function. Thanks in advance.

Upvotes: 0

Views: 849

Answers (2)

millard
millard

Reputation: 11

I found the problem... it was that because there was no timer to start the inital flashproxy.call it was executing before the flash was loaded. I just replaced

checkmap();

with another

setTimeout('checkmap()',seconds * 1000); 

Thanks everyone anyway

Upvotes: 1

Andy E
Andy E

Reputation: 344567

Did you know you have an extra/unclosed script tag in your source? This would cause problems.

<script type="text/javascript"> // This is your opening tag




<script type="text/javascript"> // Oops, this is parsed by the script engine
 var uid = new Date().getTime(); 
 var flashProxy = new FlashProxy(uid, 'js/JavaScriptFlashGateway.swf'); 
    var tag = new FlashTag('world.swf?data_file=data.xml, 600, 325); 
    tag.setFlashvars('lcId='+uid); 
    tag.write(document); 


</script> 

The above code would throw a syntax error in any javascript engine and halt further execution.

Your source is also missing a ' on the following line:

var tag = new FlashTag('world.swf?data_file=data.xml, 600, 325); 

Upvotes: 0

Related Questions