Forum Moderators: open
Please E-mail me if you know anything.
Packrat1990@msn.com
It can be difficult to post info about flash because so much of it is tied up in graphical user interface. It can be a pain posting instructions like "make a new text field, give it an instance of xyz and a var of zyx." However, to learn the actionscript part of things, it's pretty straightforward to post helpful code although it can get a bit long.
The code below will make a entry + entry = result flash movie. The important bit is the first paragraph of code, the rest could be ignored as it just "sets the stage" for the function.
1. Make a NEW flash file.
2. Copy the code below and paste it into the action panel (Window>Development Panels>Actions).
3. Test Movie. (Control>Test Movie)
//this function does the math and returns the result only when it's real
//it needs two input text fields and one dynamic text field.
// In the property window, set the "Var:" of the two inputs to line1 and line2
// and the "Var:" of the dynamic text field to outputResult
function doadd() {
var funcResult;
funcResult = (Number(line1) + Number(line2));
if ((isNaN(funcResult) == false) && isFinite(funcResult)) {
outputResult = funcResult;
} else {
//trace("Value is illegal, "+ line1 +" + "+ line2 +" is either infinite or not a number.");
}};
//Just use all the code and it will make everything it needs.
//These are the fields and the listeners
this.createTextField("mathtest", this.getNextHighestDepth(), 30, 10, 100, 22);
mathtest.border = true;
mathtest.type = "input";
mathtest.variable = "line1";
mathtest.setFocus();
mathtest.onKillFocus = function(textfield_txt:TextField) {
//trace(mathtest._name+" changed");
doadd();
};
mathtest.addListener(txtListener);
this.createTextField("mathtest2", this.getNextHighestDepth(), 30, 32, 100, 22);
mathtest2.border = true;
mathtest2.type = "input";
mathtest2.variable = "line2";
mathtest2.onKillFocus = function(textfield_txt:TextField) {
//trace(textfield_txt._name+" changed");
doadd();
};
mathtest2.addListener(txtListener);
this.createTextField("mathresult", this.getNextHighestDepth(), 30, 64, 100, 22);
mathresult.type = "dynamic";
mathresult.variable = "outputResult";
mathresult.addListener(txtListener);
// Let's make a pretty plus sign and a line:
this.createTextField("plussign", this.getNextHighestDepth(), 10, 36, 100, 22);
plussign.type = "static";
plussign.text = "+";
this.createEmptyMovieClip("dividerline", this.getNextHighestDepth());
dividerline.lineStyle(1, 0x000000, 100);
dividerline.moveTo(10, 59);
dividerline.lineTo(130, 59);
dividerline.endFill();
In the file you already have made, you should have three text fields. Two of them should be "input" fields with an instance name of "mathtest" and "mathtest2" and the third should be a "dynamic" field with an instance name of "mathresult."
You've probably never used this next value, but with the first input field selected ("mathtest") look in the property panel for a field labeled "Var:". In there, type "line1" without quotes. For "mathtest2" type in "line2" without quotes. Finally, your third field ("mathresult") should be given a "Var:" of "outputResult".
You can visually format these fields however you like.
Then paste this simplified, more streamlined code into the first frame's "actions" panel:
function doadd() {
var funcResult;
funcResult = (Number(line1) + Number(line2));
if ((isNaN(funcResult) == false) && isFinite(funcResult)) {
outputResult = funcResult;
}};
mathtest.onKillFocus = function() { doadd(); };
mathtest2.onKillFocus = function() { doadd(); };
[edited to add that Macromedia tutorial code is horribly bloated -- No one should use the first block of code I posted. Uck. /]
Also, check your stickymail, I am sending a link to a screenshot in case my description is insufficient. :)