View Full Version : Linking Javascript to Flash - Two Cases

10-05-2002, 07:00 PM
Hi, I am new to this ActionScript, I have two cases below that hopefully someone can teach me how.

I have attached a HTML file which I have designed. Actually, I want to transfer everything I have designed to the Flash format. But I don't know much about linking Javascript to Flash, because inside my HTML there exists two Javascripts. I know there is this getURL, but I don't really know the actionscript that I should write.

So the first case is the text counting one. I want to restrict the total number of characters to be less than 160. Here is the Javascript for this:

<SCRIPT language = "JavaScript">
function checkCharsRemaining ( Target )
numChars = Target.value.length;

if ( numChars > 160 ) {
Target.value = Target.value.substring(0, 160);
CharsRemaining = 0;
window.alert("Your SMS should not exceed 160 characters!");
} else {
CharsRemaining = 160 - numChars;

document.MyForm.CharsRemaining.value = 160 - numChars;

I named the message box as "Message", and in HTML, I have these two line of code as part of the Javascript:

onKeyUp="checkCharsRemaining(this)" onFocus="checkCharsRemaining(this)

The textbox with the number 160 is non-selectable, and I named it as "CharsRemaining".

How do I go about in Flash? I created one "Input Text", which is for the "Message" one; and the other is a "Dynamic Text", which is for the 160 characters. What code should I write to link them to the Javascript above?

Now for the second case. This is a bit more complicated owing to the large amount of arrays that I have created. For this one, the scenario is whenever a user selects a country from the drop-down list, the second drop-down list, named "GSMCode", will automatically lists down the selected country's available GSM code. The Javascript for this is as follows:

<SCRIPT language = "JavaScript">
var Operators = document.MyForm.GSMCode;
var aOperators = new Array (
new Array ()........//many arrays here

if (Operators.options[0].text == "") {
UpdateKeywords(document.Target.Countries.selectedI ndex);

function UpdateKeywords(index){
var selectedArray = aOperators[index];
Operators.options.length = 0;
for (var i =0; i < selectedArray.length; i++){
if( Operators.options[i] == null){
Operators.options[i] = new Option(selectedArray[i]);
} else {
Operators.options[i].text = selectedArray[i];
Operators.selectedIndex = 0;

Well, I guess this is a Flash MX question, but still I believe the concept might be the same. Now that I have created two combobox (the Flash UI component), named "Countries" and "GSMCode" respectively (same as that in HTML).

Is that anyway I can achieve the similar purpose in Flash, just like that in HTML? How do I link them to the Javascript?

Anyone's help or advice is very much appreciated and needed desperately.

Thank you in advance.

10-05-2002, 07:09 PM
Sorry, not sure just now if I have attached the file or not...

10-07-2002, 02:25 PM
well, you should be able to do both of these things inside flash with no problem... i'm tight on time this am... i want to quickly browse thru the rest of the forum, then i'm off to a meeting.
if no one has helped you when i get back from that, i will try to take some time out to do so.

10-07-2002, 03:03 PM
Hi, thanks for your time really. Actually I do try my best to learn from some sources (like Macromedia's help section), but their's is a straightforward getURL to one JavaScript function, while mine involves two targets.

Like these two lines:
onKeyUp="checkCharsRemaining(this)" onFocus="checkCharsRemaining(this)"
I am not sure where to put them...I put them after the getURL function, well nothing happens...