Copy link to clipboard
Copied
Hello, I am trying to develop a program that will place random numbers on the stage and ask the user what is the difference, sum, product, etc. The program so far is as follows:
import flash.display.MovieClip;
import flash.text.TextField;
function randomNumber(low:Number, high:Number):Number
{
return Math.floor(Math.random() * (1+high-low)) + low;
}
var add1rand:int = randomNumber(0, 10);
radnum_txt:text = format(add1rand);
The numbers get generated but when I try to display them I get the following error:
Scene 1, Layer 'Layer 1', Frame 1, Line 10 1120: Access of undefined property text.
Scene 1, Layer 'Layer 1', Frame 1, Line 10 1180: Call to a possibly undefined method format.
I have been trying for two weeks and reviewed comments from the adobe community and google searches. My system uses an AMD Phenom 9950, Quad core processor with 8GB of ram and the hard drive is a convair 128 SSD. The operating system is Windows 7 with SP1, and the flash program is Flash professional CS6, ver. 12.0.2.529. Thank you.
Copy link to clipboard
Copied
What code are you using to try to display them? What code are you suing to format the text?
Copy link to clipboard
Copied
I am using the radnum_txt:text = Format (add1rand); alond with a movie clip symbol based on a text box with an iinstance name of radnum_txt.
Copy link to clipboard
Copied
To assign text to the textfield you use the dot notation. You appear to be using a colon instead
radnum_txt.text =
as far as the format() function call goes, unless you are intending it from some other class, it is a method of the CurrencyFormatter class. So you likely need to import that class to make use of it, and you don't appear to be utilizing it with a CurrencyFormatter object instance in any way either.
import flash.globalization.CurrencyFormatter;
Check out the class thru the following page as well as the format() method it explains...
CurrencyFormatter - Adobe ActionScript® 3 (AS3 ) API Reference
Copy link to clipboard
Copied
Thank you. It worked as you described.
Copy link to clipboard
Copied
You're welcome
Copy link to clipboard
Copied
Mr. Murphy,
I created a page to gather multiple text inputs. I works in debug but when I try it in the test movie under control it hangs at the first text input field. Can you advise me ? Thank you. Here is the code.
import flash.events.Event;var FNamet=String;
var LNamet=String;
var Addresst=String;
var Cityt=String;
var Statet=String;
var ZIPt=String;stage.focus = FName;FName.addEventListener("enter", FNameinput);
LName.addEventListener("enter", LNameinput);
Address.addEventListener("enter", Addinput);
City.addEventListener("enter", Cityinput);
State.addEventListener("enter", Stateinput);
ZIP.addEventListener("enter", ZIPinput);
function FNameinput(evt_obj:Event){
FNamet = FName;
stage.focus = null;
stage.focus = LName;
}
function LNameinput(evt_obj:Event){
LNamet = LName;
stage.focus = null;
stage.focus = Address;
}function Addinput(evt_obj:Event){
Addresst = Address;
stage.focus = null;
stage.focus = City;
}function Cityinput(evt_obj:Event){
Cityt = City;
stage.focus = null;
stage.focus = State;
}function Stateinput(evt_obj:Event){
Statet = State;
stage.focus = null;
stage.focus = ZIP;
}function ZIPinput(evt_obj:Event){
ZIPt = ZIP;
stage.focus = null;
// stage.focus = ZIP;
}
James Aston
Copy link to clipboard
Copied
I know you want to focus next textField when use press Enter, but there are many mistake in your code, such as:
var LNamet=String;
String is a Class. LNamet is an instance of String. You can't put a Class into a instance. It should be:
var LNamet:String; or var LNamet:String="";
You can reference the following code:
var currentIndexUint: uint = 0;//a uint indicating which textField will be focused.
var textFieldVct: Vector.< TextField >= new < TextField > [FName, LName, Address, City, State, ZIP];
textFieldVct.fixed = true;//For better performance and reliability.
var textFieldNumUint: uint = textFieldVct.length; //a uint indicating how many textFiled in this stage.
stage.focus = FName;
stage.addEventListener(KeyboardEvent.KEY_UP, changeTabIndex);
function changeTabIndex(evt: KeyboardEvent) {
if (evt.keyCode == Keyboard.ENTER) {
if (currentIndexUint < textFieldNumUint - 1) {
trace(textFieldVct[currentIndexUint++].text);
stage.focus = null;
stage.focus = textFieldVct[currentIndexUint];
} else {
stage.focus = null;
stage.removeEventListener(KeyboardEvent.KEY_UP, changeTabIndex);
}
}
}
Copy link to clipboard
Copied
Thanks, I'll try it.
Copy link to clipboard
Copied
You are welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now