A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Send variable to Flash from Javascript

  1. #1
    Senior Member
    Join Date
    Jan 2006
    Posts
    137

    Send variable to Flash from Javascript

    I've been trying to communicate flash and javascript some time now, but I can't get Javascript to send variables to flash, just the other way around. When the .swf is done loading, it succesfully triggers the "isReady" function in Javascript, but when i try to trigger the "sendToFlash" function in Flash(via javascript), nothing happens.

    "thisMovie("myID").sendToFlash(toFlash);" this is the code I can't get to work, as you see I tried these to as well;
    document.getElementById("myID").sendToFlash(toFlas h);
    document["myID"].sendToFlash(toFlash);
    nothing triggers the code.

    I run it on a localhost(which there is nothing wrong with)

    I'm posting my entire code, but it's not a lot of code, so if you have any ideas on what it can be, please let me now

    JAVASCRIPT
    Code:
    		<script type="text/javascript" src="swfobject.js"></script>
    		<script type="text/javascript">
    		
    		
    		var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
    		var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
    		var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
    		
    		//MY CODE
    		
    		function thisMovie(movieName) {
    			var isIE = navigator.appName.indexOf("Microsoft") != -1;
    			return (isIE) ? window[movieName] : document[movieName];
    		}
    
    		function isReady(value) {
    			alert("this alert works");
    			var toFlash = "got back " + value;
    			document["myID"].sendToFlash(toFlash);
    			thisMovie("myID").sendToFlash(toFlash);
    			document.getElementById("myID").sendToFlash(toFlash);
    		}
    
    		// END MY CODE
    		
    		swfobject.registerObject("myIDs", "9.0.0", "expressInstall.swf");
    		</script>
    	
    		<object id="myID" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="500" height="400">
    		<param name="movie" value="test.swf" />
    		<param name="allowScriptAccess" value="always" />
    		<!--[if !IE]>-->
    		<object type="application/x-shockwave-flash" data="test.swf" width="500" height="400">
    		<!--<![endif]-->
    		<div>
    		<h1>Alternative content</h1>
    		<p><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>
    		</div>
    		<!--[if !IE]>-->
    		</object>
    		<!--<![endif]-->
    		</object>
    ACTIONSCRIPT
    Code:
    import flash.external.*;
    ExternalInterface.call("isReady", textMC.text);
    
    
    
    function sendToFlashs(str:String) {
    	textMC.text = "sendToFlash called with (+arguments+)" + str;
    } 
    ExternalInterface.addCallback("sendToFlash", sendToFlashs);

  2. #2
    Senior Member
    Join Date
    Jan 2006
    Posts
    137

    I Figured it out!

    Ok, I figured it out. If someone else stumbles upon this post, put a timer in the flash file, apparently the flashfile wasnt ready for javascript yet (even though it was ready to execute a javascript function, it wasnt ready to recieve) . Anyways PM me of you have any questions

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center