Get html variable from variable

  • Spiro
  • Born
  • Born
  • Spiro
  • Posts: 4

Post 3+ Months Ago

Hello All,

I would like to know how i can check a HTML textbox variable from flash?

:wink:
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Abelius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 260
  • Loc: Miami Beach, FL, USA

Post 3+ Months Ago

You mean, pass it as a variable to some JavaScript, or ASP page?
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

Here's one way.

For examples sake I''ve used a simple movie consisting of only a dynamic textbox with "flashBox" as the variable & a button.

Here's the code used for the button,
Code: [ Select ]
button.onPress = function(){
    fscommand("getValueOf",["htmlBox","flashBox"]);
}
  1. button.onPress = function(){
  2.     fscommand("getValueOf",["htmlBox","flashBox"]);
  3. }

"getValueOf" will be the name of our method so to speak, "htmlBox" will be the ID of the textbox in HTML we want returned & "flashBox" is the variable that will recieve the variable. (note that fscommand allows 1 or 2 arguments, multiple params must be encased in an array)

We select publish settings from the file menu(ctrl+shft+F12), & select "Flash with fscommand" from the "template" dropdown. (make sure you dont publish over an existing page)
This publishes a template we can use to have Flash and Javascript communicate with eachother.

Code: [ Select ]
<SCRIPT LANGUAGE=JavaScript>
<!--
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the the FSCommand messages in a Flash movie
function myFSCommand_DoFSCommand(command, args) {
 var myFSCommandObj = InternetExplorer ? myFSCommand : document.myFSCommand;
//
//your code here
//
}
// Hook for Internet Explorer
if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 &&
     navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
    document.write('<SCRIPT LANGUAGE=VBScript\> \n');
    document.write('on error resume next \n');
    document.write('Sub myFSCommand_FSCommand(ByVal command, ByVal args)\n');
    document.write(' call myFSCommand_DoFSCommand(command, args)\n');
    document.write('end sub\n');
    document.write('</SCRIPT\> \n');
}
//-->
</SCRIPT>
<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ID="myFSCommand" WIDTH="200" HEIGHT="200" ALIGN="">
<PARAM NAME=movie VALUE="myFSCommand.swf">
<PARAM NAME=quality VALUE=high>
<PARAM NAME=bgcolor VALUE=#FFFFFF>
<EMBED src="myFSCommand.swf" quality=high bgcolor=#FFFFFF WIDTH="200" HEIGHT="200" swLiveConnect=true ID="myFSCommand" NAME="myFSCommand" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
</OBJECT>
</BODY>
</HTML>
  1. <SCRIPT LANGUAGE=JavaScript>
  2. <!--
  3. var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
  4. // Handle all the the FSCommand messages in a Flash movie
  5. function myFSCommand_DoFSCommand(command, args) {
  6.  var myFSCommandObj = InternetExplorer ? myFSCommand : document.myFSCommand;
  7. //
  8. //your code here
  9. //
  10. }
  11. // Hook for Internet Explorer
  12. if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 &&
  13.      navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
  14.     document.write('<SCRIPT LANGUAGE=VBScript\> \n');
  15.     document.write('on error resume next \n');
  16.     document.write('Sub myFSCommand_FSCommand(ByVal command, ByVal args)\n');
  17.     document.write(' call myFSCommand_DoFSCommand(command, args)\n');
  18.     document.write('end sub\n');
  19.     document.write('</SCRIPT\> \n');
  20. }
  21. //-->
  22. </SCRIPT>
  23. <OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ID="myFSCommand" WIDTH="200" HEIGHT="200" ALIGN="">
  24. <PARAM NAME=movie VALUE="myFSCommand.swf">
  25. <PARAM NAME=quality VALUE=high>
  26. <PARAM NAME=bgcolor VALUE=#FFFFFF>
  27. <EMBED src="myFSCommand.swf" quality=high bgcolor=#FFFFFF WIDTH="200" HEIGHT="200" swLiveConnect=true ID="myFSCommand" NAME="myFSCommand" ALIGN="" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer"></EMBED>
  28. </OBJECT>
  29. </BODY>
  30. </HTML>


Now we need to make some changes to this template,
Note the function declaration,
Code: [ Select ]
function myFSCommand_DoFSCommand(command, args) {

The part before "_DoFSCommand" MUST match the ID of the movie calling it. If your movies ID is "myMovie" the function would be "myMovie_DoFSCommand".

Now for telling Flash what the value of the box is (you may have noticed there was nothing being assigned in the movie itself ie "var = fscommand")
Inside the function where it says "//your code here" we need theese lines.
Code: [ Select ]
if(command = "getValueOf"){
    myArgs = args.split(",");
    myFSCommandObj.SetVariable(myArgs[1], document.getElementById(myArgs[0]).value);
 }
  1. if(command = "getValueOf"){
  2.     myArgs = args.split(",");
  3.     myFSCommandObj.SetVariable(myArgs[1], document.getElementById(myArgs[0]).value);
  4.  }


The "if('command' == 'getValueOf')" is for separating different function possibilities since we have to use the same _DoFSCommand.. for everything with that movie.

The "myArgs = args.split(',')" is taking our arguments which flash seems to think would be better passed as a string & creating a usable Javascript array out of them.

The template has allready figured out wheather to use "document.movieId" or not with "var myFSCommandObj =..." So we get the value of the requested element & return it with "SetVariable()".

SetVariable takes 2 params, the variable in the movie to set... & the value to pass to it so,
Code: [ Select ]
myFSCommandObj.SetVariable(myArgs[1], document.getElementById(myArgs[0]).value);

Will take the first argument passed from flash & find the value of a HTML element with that ID, then it will pass it to the variable named in the second argument.

If you want flash to react to the variable being changed you will need to either set a timeout for flash to wait before trying to use the variable, or setup an object to watch the variable & fire when the variable changes.
  • Spiro
  • Born
  • Born
  • Spiro
  • Posts: 4

Post 3+ Months Ago

What an amazingly comprehensive answer, thank you so much.
  • Abelius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 260
  • Loc: Miami Beach, FL, USA

Post 3+ Months Ago

Whoa, joebert! :)

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 16 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.