Capturing text input
Copy link to clipboard
Copied
This question was posted in response to the following article: http://help.adobe.com/en_US/as3/dev/WS8d7bb3e8da6fb92f-20050207122bd5f80cb-7ff7.html
Copy link to clipboard
Copied
Keep getting an error message fom the above code saying that package cannot be nested. Also Package unexpected
Copy link to clipboard
Copied
Hmm. I copy & pasted the code into a new ActionScript project in Flash Builder. It compiled and ran with no problems.
I'm not sure what to say. Maybe double-check that you copied the whole thing. Also, I ran it in a browser. Are you trying it in AIR or on a device?
HTH,
Randy Nielsen
Senior Content and Community Lead
Copy link to clipboard
Copied
Thanks for getting back so quickly. No I tried it a number of times on my Apple mac. Copied and pasted a number of times also into a new file. I'm using Flash C5 professional. I will try again later. Thanks in the meantime.
Sent from my iPhone
Copy link to clipboard
Copied
Hi yes tried it again in a new file in Flash C5 Professional and it says that package can be nested. Pity
Copy link to clipboard
Copied
Would really like to get a solution to this problem have tried again on a brand new file with the above code and I get error 1037 Package can not be nested. I have spend days trying to get a basic capture text input frame and everything on the net comes up with a similar message usually to do with not being possible to nest package. Im using Flash professional CS5.5 to be exact. Im pretty new to this software. Would really appreciate some suggestions. Im using a MacBook Pro. All help greatfully received
Copy link to clipboard
Copied
I looked at the instructions for running class-based AS examples and noticed one thing. They say that to run in Flash Pro, you must inherit from Sprite, not MovieClip. So try adding an import and extend from MovieClip, something like this:
import flash.display.MovieClip;
public class CaptureUserInput extends MovieClip
Hope this helps,
-Randy
Copy link to clipboard
Copied
Great thanks for that will look Into it.
Sent from my iPhone

Copy link to clipboard
Copied
The code, as is, works just fine in Flash - and you can extend Sprite or MC. Be sure to place the .as file in the same folder as your .fla, and the name of the class file must be CaptureUserInput.as
Copy link to clipboard
Copied
Thanks again for your assistance apologies for the delay getting back. Im
afraid still no success. I created a folder on my desktop and called it
Text Capture Flash. Into this folder I created and saved a CS5.5 file
called CaptureUserinput.fla and another called CaptureUserinput.as
Now I updated the Document class as follows;
package
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.text.*;
import flash.events.*;
public class CaptureUserInput extends MovieClip
{
private var myTextBox:TextField = new TextField();
private var myOutputBox:TextField = new TextField();
private var myText:String = "Type your text here.";
public function CaptureUserInput()
{
captureText();
}
public function captureText():void
{
myTextBox.type = TextFieldType.INPUT;
myTextBox.background = true;
addChild(myTextBox);
myTextBox.text = myText;
myTextBox.addEventListener(TextEvent.TEXT_INPUT,
textInputCapture);
}
public function textInputCapture(event:TextEvent):void
{
var str:String = myTextBox.text;
createOutputBox(str);
}
public function createOutputBox(str:String):void
{
myOutputBox.background = true;
myOutputBox.x = 200;
addChild(myOutputBox);
myOutputBox.text = str;
}
}
}
Alas when I tested the movie while this time there were no error messages
(Progress I must admit), there was no text box just a blank swf.
Copy link to clipboard
Copied
Ah yes I finally got it! Ignore the last message. The pints are on me
tonight! much obliged for the input thanks again
Copy link to clipboard
Copied
Works fine, except that the last character entered in myTextBox does not show in myOutputBox. Solution?
Copy link to clipboard
Copied
Is this as flexible as the operating system of the game player- e.g. I want to allow the use to enter Kanji (Japanese Pictograms). Can he do it if his computer has the means (IME)?
Copy link to clipboard
Copied
@cloa513,
I've never done this myself, so I can't tell you for sure, but I just checked the ActionScript Reference for flash.text.TextField, and it contains events for IME and softkeyboard.
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/text/TextField.html
Hope this helps,
Randy Nielsen
Product Integration Manager, Creative Cloud Learning & Training
Adobe

