limjn
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;
}
</SCRIPT>
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;
}
</SCRIPT>
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.
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;
}
</SCRIPT>
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;
}
</SCRIPT>
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.