Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 25
  1. #1
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to send variables to flash using externalinterface.addcallback.

    Believe it or not, i have searched google for the last 3 hours and i can not seem to find an example of sending a variable together with a function call to flash using externalinterface.addcallback.

    for example i just want to trigger the "receiver" function located in my actionscript below. i want to send the variables "attachedvariable1" and "attachedvariable2"

    Actionscript
    Code:
    function Receiver(attachedvariable1, attachedvariable2)
    {
    externalinterface.call("alert", attachedvariable1, attachedvariable2);
    }


    how can i send these variables only using externalinterface.addcallback? or can this not be done without externalinterface.call ?

  2. #2
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Here is some code I wrote a while ago that worked. Maybe it will help?

    Javascript

    Code:
    			// Provides the proper address for the movie depending on browser
    			function getFlashMovie(movieName) {
    			  	var isIE = navigator.appName.indexOf("Microsoft") != -1;
    			  	return (isIE) ? window[movieName] : document[movieName];
    			}
    
    			function playMovie() { 
    				getFlashMovie("video").JStoASviaExternalInterface("start");
    			}
    Actionscript

    Code:
    function closeIt() {
    	videoPlayer._alpha = 0;
    	fadecheck = 0;
    	endcheck = 0;
    	ns.seek(0);
    	var callElement = ExternalInterface.call("closeWindow");
    }
    
    function getTextFromJavaScript(str:String):Void {
    		if (str = "start") {
    startVideo();
    }
    }
    ExternalInterface.addCallback("JStoASviaExternalInterface", this, getTextFromJavaScript);
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  3. #3
    Regular Coder
    Join Date
    Nov 2008
    Posts
    165
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wow that worked... thank you very very very much .....

    you guys are the best...

  4. #4
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    You are welcome, glad you were able to make it work!
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  5. #5
    New to the CF scene
    Join Date
    Feb 2009
    Location
    Canada
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript to ActionScript 2 Communication

    I basically want Javascript to interact with the SWF ,calling from Javascript to ActionScript 2. I am on Flash CS3 ActionScript 2

    Here's the code placed on frame 1 of my fla;

    HS_Film_Button.onRelease = function ()
    {
    gotoAndStop(2);
    flash.external.ExternalInterface.call("firehs");
    };

    Once on frame 2 of my movie, a Javascript element is displayed. When clicking on the Javascript element's "close" button , I want my movie to go to frame 1.
    Here's the code to be placed in the head of my html for telling the Javascript "close" button to tell Flash to go to frame 1;

    <script type="text/javascript">
    hs.Expander.prototype.onBeforeClose = function (sender) {
    -here's the line of code I am missing-;
    }
    </script>

    I am missing the line of code that would make the swf go to frame 1
    I know that the code line would designate "frame 1" in Flash as "frame 0"

    Looking forward to your help!

    I suspect it has to do with he addCallback() method in flash.
    in My HTML body....
    AC_FL_RunContent(
    'codebase',
    'name', 'Hardy_Art_Book',
    'id', 'Hardy_Art_Book',
    'movie', 'Hardy_Art_Book',
    Last edited by HardyArt; 02-02-2009 at 05:10 PM.

  6. #6
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Code:
    <script type="text/javascript">
    
    function getFlashMovie(movieName) {
      	var isIE = navigator.appName.indexOf("Microsoft") != -1;
     	return (isIE) ? window[movieName] : document[movieName];
    }
    
    hs.Expander.prototype.onBeforeClose = function (sender) {
    getFlashMovie("Hardy_Art_Book").goToHome();
    }
    </script>
    That would be the JS, and then you need a function named goToHome in AS which then has the code to move the movie to frame 1. Basically JS can only call a function in AS, not actually send some AS. Otherwise that would be a huge security problem, just think if anyone could control the SWF through JS freely!
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  7. #7
    New to the CF scene
    Join Date
    Feb 2009
    Location
    Canada
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Since I posted this = I got it to work with the following html head js code = so simple I am still in shock....

    <script type="text/javascript">
    hs.Expander.prototype.onBeforeClose = function (sender) {
    Hardy_Art_Book.GotoFrame(0);
    }
    </script>


    What you came up with looks like a good thing.... after reading your input info about the "security issue" my question now would be.... is my coding solution within the bounds of what you were enounciating? If you think it is; then all is good and it would still make your solution = one that I do appreciate very much indeed. When you get the help.....and as well done as yours, things feel much better at the end of the day for sure!
    Cheers!
    Pierre

  8. #8
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    No you are fine, the security issue is not you, but the restrictions placed by Flash. Nice work
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  9. #9
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have a question though, about this code, what do I need that closeIt function?

    Quote Originally Posted by jeremywilken View Post
    Here is some code I wrote a while ago that worked. Maybe it will help?

    Javascript

    Code:
    			// Provides the proper address for the movie depending on browser
    			function getFlashMovie(movieName) {
    			  	var isIE = navigator.appName.indexOf("Microsoft") != -1;
    			  	return (isIE) ? window[movieName] : document[movieName];
    			}
    
    			function playMovie() { 
    				getFlashMovie("video").JStoASviaExternalInterface("start");
    			}
    Actionscript

    Code:
    function closeIt() {
    	videoPlayer._alpha = 0;
    	fadecheck = 0;
    	endcheck = 0;
    	ns.seek(0);
    	var callElement = ExternalInterface.call("closeWindow");
    }
    
    function getTextFromJavaScript(str:String):Void {
    		if (str = "start") {
    startVideo();
    }
    }
    ExternalInterface.addCallback("JStoASviaExternalInterface", this, getTextFromJavaScript);

  10. #10
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Function closeIt is what can be called from Flash to activate a Javascript function using this

    Code:
    var callElement = ExternalInterface.call("closeWindow");
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  11. #11
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    externalInterface stop FLV playback

    Ok so I've just read your thread above and it all seems so easy, as do all the tutorials that I've been through on this as a newbie web dev, but for whatever reason I just can't make this work???

    I'm trying to stop the playback of an SWF/FLV file nested into a div when this div is hidden through navigation.

    I think my brain must just be mush by now....any help would be greatly appreciated.

    AS CODE

    Code:
    import flash.external.ExternalInterface;
    
    ExternalInterface.addCallback("stopFLV", stopFLV);
    
    function stopFLV() {
        FLV_Promo.stop();
    }
    HTML CODE

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    
    <script language="javascript">
    
    	function callFlash()  
    {  
    // Get a reference to the player  
    var player = null;  
      
    if (document.all)  
    player = document.all("flashPlayer");  
    else  
    player = document.getElementById("flashPlayerEmbedded");  
    
    }
    
    function stopFLV()
    {
    	player.stopFLV();
    }
    
    	function showPage1() {
    				document.getElementById('Page1').style.visibility='visible';
    				document.getElementById('Page2').style.visibility='hidden';
    				document.getElementById('Page3').style.visibility='hidden';
    				stopFLV();
    				
    	
    		    }	
    	function showPage2() {
    				document.getElementById('Page1').style.visibility='hidden';
    				document.getElementById('Page2').style.visibility='visible';
    				document.getElementById('Page3').style.visibility='hidden';
    	
    		    }
    	function showPage3() {
    				document.getElementById('Page1').style.visibility='hidden';
    				document.getElementById('Page2').style.visibility='hidden';
    				document.getElementById('Page3').style.visibility='visible';
    				stopFLV();
    	
    		    }
    
        AC_FL_RunContent = 0;</script>
    	<script src="AC_RunActiveContent.js" language="javascript"></script>
    </head>
    
    <body>
    
    <div id="Page1" style="visibility:visible"> PAGE_1_CONTENT</div>
    
    <div id="Page2" style="visibility:hidden">
    
    	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="554" height="478" id="promo" align="middle">
    	<param name="allowScriptAccess" value="always" />
    	<param name="allowFullScreen" value="false" />
    	<param name="movie" value="promo.swf" />
        <param name="loop" value="false" />
        <param name="menu" value="false" />
        <param name="quality" value="high" />
        <param name="wmode" value="transparent" />
        <embed src="promo.swf" loop="false" menu="false" quality="high" wmode="transparent" width="554" height="478" name="promo" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>
    	</object>
    
    
    
    </div>
    
    <div id="Page3" style="visibility:hidden"> PAGE_3_CONTENT</div>
    
    <img name="BTN_HOME" src="images/BTN_HOME_OFF.jpg" width="67" height="28" alt=""onclick="showPage1();">
    <img name="BTN_HOME" src="images/BTN_HOME_OFF.jpg" width="67" height="28" alt=""onclick="showPage2();">
    <img name="BTN_HOME" src="images/BTN_HOME_OFF.jpg" width="67" height="28" alt=""onclick="showPage3();">
    
    </body>
    </html>

  12. #12
    New to the CF scene
    Join Date
    May 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello. I am a newbie to programming in whole and i am really stressed. I cant for the like of me figure out how to get my flash banner to stop using javascript in my dreamweaver page. I am so lost. I have tried all kinds of codes and tried to manipulate it but i really just need help. My bosses are killing me here. Please HELP.

  13. #13
    Senior Coder gnomeontherun's Avatar
    Join Date
    Sep 2007
    Location
    Houston
    Posts
    2,846
    Thanks
    10
    Thanked 238 Times in 229 Posts
    Ok, you need to show us some code or a link, and explain what the problem is. Flash doesn't use Javascript...?

    If your boss is mad, then they should put you through a course to learn this stuff.
    jeremy - gnomeontherun
    Educated questions often get educated answers, and simple questions often get simple answers.

  14. #14
    New to the CF scene
    Join Date
    May 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dont really have a specific code. I am trying to find one that i could use.
    Currently, i just have a slide show done in Action Script 2.0 - flash Player 8 and all it has is the following code:
    _level2.imageloaded = "1";

    I have a html menu that uses the following code:

    <script type="text/javascript" language="JavaScript1.2">
    <!--
    beginSTM("lokbdhr","static","0","0","left","false","false","310","50","0","0","","blank.gif");
    beginSTMB("auto","0","0","vertically","arrow_r.gif","0","0","1","2","transparent","","tiled","#99999 9","1","solid","0","Normal","50","1","1","0","0","0","0","4","#000000","false","#999999","#999999"," #999999","complex");
    appendSTMI("false","The&nbsp;Company","left","middle","","","-1","-1","0","normal","#fbf021","#fbf021","","0","-1","-1","wireliinebackgroundlogo.png","blank.gif","1","1","0","","","_self","Arial","10pt","#000000","bol d","italic","none","Arial","10pt","#333333","bold","italic","none","0","solid","#ffffff","#ffffff"," #ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","","","","tiled","tiled");
    appendSTMI("false","Company&nbsp;History","left","middle","","","-1","-1","0","normal","#cc0000","#fbf021","","0","-1","-1","wireliinebackgroundlogoinred.png","wireliinebackgroundlogoinred.png","1","1","0","","http://www.tuckerenergy.com/thecompany/history.htm","_self","Arial","10pt","#ffffff","bold","italic","none","Arial","10pt","#333333","bold" ,"italic","none","0","solid","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff"," #ffffff","http://www.tuckerenergy.com/thecompany/history.htm","","","tiled","tiled");
    appendSTMI("false","Our&nbsp;Mission/Values/Vision","left","middle","","","-1","-1","0","normal","#cc0000","#fbf021","","0","-1","-1","wireliinebackgroundlogoinred.png","wireliinebackgroundlogoinred.png","1","1","0","","http://www.tuckerenergy.com/thecompany/misvalvis.htm","_self","Arial","10pt","#ffffff","bold","italic","none","Arial","10pt","#333333","bol d","italic","none","0","solid","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff" ,"#ffffff","http://www.tuckerenergy.com/thecompany/misvalvis.htm","","","tiled","tiled");
    appendSTMI("false","Corporate&nbsp;HSSE&nbsp;Policy","left","middle","","","-1","-1","0","normal","#cc0000","#fbf021","","0","-1","-1","wireliinebackgroundlogoinred.png","wireliinebackgroundlogoinred.png","1","1","0","","http://www.tuckerenergy.com/thecompany/grouphse.htm","_self","Arial","10pt","#ffffff","bold","italic","none","Arial","10pt","#333333","bold ","italic","none","0","solid","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff", "#ffffff","http://www.tuckerenergy.com/thecompany/grouphse.htm","","","tiled","tiled");
    appendSTMI("false","Critical&nbsp;Areas&nbsp;Policy&nbsp;Statement","left","middle","","","-1","-1","0","normal","#cc0000","#fbf021","","0","-1","-1","wireliinebackgroundlogoinred.png","wireliinebackgroundlogoinred.png","1","1","0","","http://www.tuckerenergy.com/thecompany/CriticalAreas.htm","_self","Arial","10pt","#ffffff","bold","italic","none","Arial","10pt","#333333", "bold","italic","none","0","solid","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#fff fff","#ffffff","http://www.tuckerenergy.com/thecompany/CriticalAreas.htm","","","tiled","tiled");
    appendSTMI("false","Quality&nbsp;Management&nbsp;System","left","middle","","","-1","-1","0","normal","#cc0000","#fbf021","","0","-1","-1","wireliinebackgroundlogoinred.png","wireliinebackgroundlogoinred.png","1","1","0","","http://www.tuckerenergy.com/services/qms/Quality_Manag_Sys.htm","_self","Arial","10pt","#ffffff","bold","italic","none","Arial","10pt","#3333 33","bold","italic","none","0","solid","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff"," #ffffff","#ffffff","http://www.tuckerenergy.com/services/qms/Quality_Manag_Sys.htm","","","tiled","tiled");
    appendSTMI("false","TES&nbsp;Product&nbsp;Lines","left","middle","","","-1","-1","0","normal","#fbf021","#fbf021","","0","-1","-1","wireliinebackgroundlogo.png","blank.gif","1","1","0","","","_self","Arial","10pt","#000000","bol d","italic","none","Arial","10pt","#000000","bold","italic","none","0","solid","#ffffff","#ffffff"," #ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","","","","tiled","tiled");
    appendSTMI("false","Wireline&nbsp;Services","left","middle","","","-1","-1","0","normal","#cc0000","#fbf021","","0","-1","-1","wireliinebackgroundlogoinred.png","wireliinebackgroundlogoinred.png","1","1","0","","http://www.tuckerenergy.com/services/wireline/main.htm","_self","Arial","10pt","#ffffff","bold","italic","none","Arial","10pt","#333333","bold","i talic","none","0","solid","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ff ffff","http://www.tuckerenergy.com/services/wireline/main.htm","","","tiled","tiled");
    appendSTMI("false","Cementing&nbsp;Services","left","middle","","","-1","-1","0","normal","#cc0000","#fbf021","","0","-1","-1","wireliinebackgroundlogoinred.png","wireliinebackgroundlogoinred.png","1","1","0","","http://www.tuckerenergy.com/services/pumping/cementing.htm","_self","Arial","10pt","#ffffff","bold","italic","none","Arial","10pt","#333333","bol d","italic","none","0","solid","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff" ,"#ffffff","http://www.tuckerenergy.com/services/pumping/cementing.htm","","","tiled","tiled");
    appendSTMI("false","Completion&nbsp;Services","left","middle","","","-1","-1","0","normal","#cc0000","#fbf021","","0","-1","-1","wireliinebackgroundlogoinred.png","wireliinebackgroundlogoinred.png","1","1","0","","http://www.tuckerenergy.com/services/completion/main.htm","_self","Arial","10pt","#ffffff","bold","italic","none","Arial","10pt","#333333","bold","i talic","none","0","solid","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ff ffff","http://www.tuckerenergy.com/services/completion/main.htm","","","tiled","tiled");
    appendSTMI("false","Coiled&nbsp;Tubing&nbsp;Services","left","middle","","","-1","-1","0","normal","#cc0000","#fbf021","","0","-1","-1","wireliinebackgroundlogoinred.png","wireliinebackgroundlogoinred.png","1","1","0","","http://www.tuckerenergy.com/services/coiled tubing/main.htm","_self","Arial","10pt","#ffffff","bold","italic","none","Arial","10pt","#333333","bold","i talic","none","0","solid","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ff ffff","http://www.tuckerenergy.com/services/coiled tubing/main.htm","","","tiled","tiled");
    appendSTMI("false","DrillingServices","left","middle","","","-1","-1","0","normal","#cc0000","#fbf021","","0","-1","-1","wireliinebackgroundlogoinred.png","wireliinebackgroundlogoinred.png","1","1","0","","http://www.tuckerenergy.com/services/drilling/main.htm","_self","Arial","10pt","#ffffff","bold","italic","none","Arial","10pt","#333333","bold","i talic","none","0","solid","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ff ffff","http://www.tuckerenergy.com/services/drilling/main.htm","","","tiled","tiled");
    appendSTMI("false","Treating&nbsp;Chemicals","left","middle","","","-1","-1","0","normal","#cc0000","#fbf021","","0","-1","-1","wireliinebackgroundlogoinred.png","wireliinebackgroundlogoinred.png","1","1","0","","http://www.tuckerenergy.com/services/production chemicals/default.htm","_self","Arial","10pt","#ffffff","bold","italic","none","Arial","10pt","#333333","bold" ,"italic","none","0","solid","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff"," #ffffff","http://www.tuckerenergy.com/services/production chemicals/default.htm","","","tiled","tiled");
    appendSTMI("false","TES&nbsp;News&nbsp;Archives","left","middle","","","-1","-1","0","normal","#fbf021","#cc0000","","0","-1","-1","wireliinebackgroundlogo.png","blank.gif","1","1","0","","http://www.tuckerenergy.com/news/main.htm","_self","Arial","10pt","#000000","bold","italic","none","Arial","10pt","#ffffff","bold","i talic","none","0","solid","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ff ffff","http://www.tuckerenergy.com/news/main.htm","","","tiled","tiled");
    appendSTMI("false","TES&nbsp;Careers","left","middle","","","-1","-1","0","normal","#fbf021","#cc0000","","0","-1","-1","wireliinebackgroundlogo.png","blank.gif","1","1","0","","http://www.tuckerenergy.com/careers/default.htm","_self","Arial","10pt","#000000","bold","italic","none","Arial","10pt","#ffffff","bold" ,"italic","none","0","solid","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff"," #ffffff","http://www.tuckerenergy.com/careers/default.htm","","","tiled","tiled");
    appendSTMI("false","TES&nbsp;Locations","left","middle","","","-1","-1","0","normal","#fbf021","#cc0000","","0","-1","-1","wireliinebackgroundlogo.png","blank.gif","1","1","0","","http://www.tuckerenergy.com/locations/default.htm","_self","Arial","10pt","#000000","bold","italic","none","Arial","10pt","#ffffff","bold" ,"italic","none","0","solid","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff","#ffffff"," #ffffff","http://www.tuckerenergy.com/locations/default.htm","","","tiled","tiled");
    endSTMB();
    endSTM();
    //-->

    I am trying to figure out how to use the externalinterface addCallback to make it to where when a user hits a menu button, the flash banner stops.

    Thanks Jeremywilken.

    yes, my boss said he'll send me when we get some funds. Like he does not have enough. oh well.

  15. #15
    New to the CF scene
    Join Date
    May 2009
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if you want to look at my website it is at www.tuckerenergy.com

    I'm not sure if that would help you to understand what i am trying to do any better.


 
Page 1 of 2 12 LastLast

Posting Permissions

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