views:

208

answers:

1

I have a text box (dynamic) whose value is being changed by javascript using the setVariable method.

Bascially I'm now stuck in getting the flash application to recognise when the text box value has been changed, onKeyUp etc.. do not seem to work.

The below code works if the user types in to the box, but if it is changed via JS it does not pick up the change, therfore not populating my variables. What Listener should i be using?

someListener = new Object();
someListener.onKeyUp = function () {
 var StationName = StationBox;
 var Test = "the station is:" + StationName;
 trace(Test);
 _global.StationNameGlobal = StationBox;
 OutputTxt = "TEST";
}
Key.addListener(someListener);
A: 

Instead of directly manipulating the data inside the text box, instead route your javascript call to an internal actionscript function that will both replace/append the data and programatically trigger your onChange function synchronously.

For instance, if you have a flash movie and give the object and the embed the same ID example:


<object ID="myMovie" CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" WIDTH="230" HEIGHT="50" CODEBASE="download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">
<PARAM NAME="MOVIE" VALUE="some.swf">
<param NAME="PLAY" VALUE="true">
<param NAME="LOOP" VALUE="false">
<param NAME="QUALITY" VALUE="high">
<param NAME="MENU" VALUE="false">
<param NAME="WMODE" VALUE="transparent">
<embed ID="myMovie" wmode="transparent" SRC="some.swf" WIDTH="230" HEIGHT="50" PLAY="true" LOOP="false" QUALITY="high" MENU="false" TYPE="application/x-shockwave-flash" PLUGINSPAGE="www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
</embed>
</object>

You can then trigger actionscript functions and change variables inside of flash using a simple javascript such as:


function changeTheField(incomingText) {
    var controlledMovie = document.myMovie;
    controlledMovie.SetVariable("_root.myTextAreaConents", incomingText);
}

Now you can easily attach a listener to the variable, 'myTextAreaConents' in the example above, waiting for changes. At which time it would fire off a function to populate the variables' new contents into the text area.

drlouie - louierd
Like the ExternalInterface class?
Richard
I've updated my response with an example. Let me know if you have any more questions.
drlouie - louierd