textfield.text not showing every characters - actionscript-3

I have a setup a PageHolder class (based on MovieCLip) that displays a doted area with a (page) number in the middle.
Now attempting to populate my LayoutPane, I create new instances of of PageHolder whose constructor is tasked to set the text value of its only Texfield to the value specified in the new PageHolder parameter.
The problem here is that only the character present in the Library Object will display at run time.
For example, I have setup my PageHolder object with a text field containing the number "0". Now at run time, every instance of PageHolder is blank except fro the one that I passed a "0" as part of the init parameter (10,20,30,...) and on those pages, only the "0" is showing. If I change the original object to display a "1" instead, then every "1" of the page number that contains a "1" show ups.
Can somebody shed some light on this?
package
{
import flash.display.MovieClip;
public class LayoutPage extends MovieClip
{
public function LayoutPage(page:uint)
{
pageNumber_txt.defaultTextFormat = pageNumber_txt.getTextFormat();
pageNumber_txt.text = String(page);
}
}
}

You may need to embed the font you are using for the text field.
Select the text field you have put in your PageHolder class and click the Embed button underneath the font family drop-down box, then check the item labeled 'Numerals[0..9]' and click OK.

Related

How to create a new text field via a button in as3?

I've been having this problem forever now. All I want to do is create a button that adds a new (input) text field that is located right beneath the previous one (Like perhaps, a user creating a bullet list with a certain amount of items).
Here is the code I have so far (that pertains to the topic)
function addCompanySlotButton(b:MouseEvent){
for(var i:Number = 0;i<slotArray.length;i++){ //slotArray holds the number of text fields (slots) that exist.
company_slot.name = "slot"+(i); //This is supposed to name the newly-created text field by its index number. (company_slot is just a variable name for the text fields)
company_slot.y = 30*slotArray.length; //This is supposed to move the newly-created index slot down by 30 * (whatever it's index number is).
company_slot.x = 75;
company_container.addChild(company_slot); //company_container is just a display object that shows the text fields/company slots.
}
slotArray.push(company_slot);
trace(slotArray.length); //This number increases every time the button is pressed, so I know for sure that there is more than one text field.
}
However, it appears as though all of the text fields are in the same spot, and whenever the button is pressed, ALL of them move instead of just one. I'm pretty new to actionscript (and coding in general), so any help is greatly appreciated.

AS3/Air/Starling mobile app textinput class and how to get text value when in a class

I have a mobile app built in as3/air for mobile devices and I am wondering what the best approach to handle textinput fields are.
What I mean is I have multiple input fields on multiple screens. The inputs have a label (textfield), background color under the label (quad) and an input (textinput). Some are password, some are not. Some are different width/heights, multi-line/single line etc. All however use embedded fonts, have a name and ID assigned etc.
I have created a class file that extends Sprite and built all the components of the textinput (textfield, quad, textinput) so my other classes/screens can just create a new instance of this class passing custom values.
var textField:TextFieldClass = new TextFieldClass();
textField.DrawTextField(name, ID, width, height, isPassword, hasLabel, labelPosition etc);
The above works great. I can reuse the class to draw multiple textinput on screen with minimal code however I am having trouble getting the text value/ID/name when there are multiple instances.
I have tried adding each textField instance into an array and iterating through but that gets x number of the last textField instance e.g. if first instance is named txtEmail and the second is txtPassword, I get 2 txtPasswords.
I have also tried getChildByName and specifying the name of the textinput but when I use txtEmail I get a cannot access null value but txtPassword works.
Maybe I am going about this wrong so happy to use a better approach if one exists (which I am sure there is). Basically I would like to have a reusable textinput class that allows custom design (quads, fonts etc) without having to copy paste the entire textinput code for each new input field.
Thanks

Dynamic text field in Frames not changing text in actionscript 3

Dynamic Text field not updating in actionscript when in 2nd Frame
I am having a movie clip with two frames. In 2nd frame there is a movie clip which has a text field.
My goal is to on some event I will move to the frame that has the movie clip with text field.
I am trying to update the text field with a code something like:-
public function updateTxtFld(e:Event)
{
//My goal is to on some event show the movie clip with the text field
questBG.gotoAndStop("glow");
arrowText.text = "some text"; //arrowTextt has been assigned with the correct text field
}
After some time I again move back to the frame which has no movie clip thus hiding the movie clip
public function hide()
{
questBG.gotoAndStop("idle");
}
The text field does not get updated from the actionscript even though trace(arrowText.text) shows the updated value.
Now if I remove frames from the movie clip & modify the updateTxtFld() like
public function updateTxtFld(e:Event)
{
(questBG.getChildByName('arrowBG') as Sprite).visible = true;
arrowText.text = "some text"; //arrowTextt has been assigned with the correct text field
}
Then it works fine with the text getting updated in the text field. It seems there seems to be some problem in updating dynamic text field in frames.
I have also verified that text embedding is fine in both the cases
I have created the flas using CS Professional 5.5 & I am trying to change the text field using actionscript running in Flex Builder 4.7. Let me know if anyone need the fla (both working & non-working version).
Not sure if you solved this yourself, but the best way to do this would be to have the text field in both the frames, but just either move it on or off stage by changing either the X or Y value when you want to show or hide it, or similar to what you stated, by changing the visibility or alpha of the text field.
Try
questBG.gotoAndStop("glow");
trace (questBG.arrowText);
questBG.arrowText.text = "some text";

Want help to create a list in as3/flash

I want to create a scrollable list in flash/as3 and the important thing is.... if the user wants to move some list item up or down... he can do that by dragging the item... so when he press and hold on an item... the item will become drag-able and as the user moves it up or down the list, the other items should slide to the empty space. Its the same behavior seen in smartphones....
I'll figure out the creation, data filling, scrolling, and other mouse interaction events.... i just want help with this one behavior....of changing the order of items by dragging them. If only someone can just provide the basic algorithm or any idea how this can be achieved.. it will be enough.
​Thanks in advance
EDITS :
First of all... i apologize for not posting any details about the question... (this is my first post to this site) and hence i am adding all the research and what i have done so far.
the list is part of a big project hence i cannot share the whole code.
WHAT I HAVE ALREADY DONE :
i have created a mask, a container, a scroll bar to scroll the container, items to add into the list, methods to add items, remove items and arrange them according to the order.
hence it is a scrallable and working list.
the whole thing is in as3 and flash only.
i don't know flex and i don't want to use it either.
WHAT I WANT NEXT :
i want to change the order of these items by (mouse_down on an item -> drag it up/down -> mouse_up at the position) sequence.
If anyone wants more details i can share it.
Thanks in advance.. :)
Add a simple List component to an application
In this example, the List consists of labels that identify car models and data fields that contain prices.
Create a new Flash (ActionScript 3.0) document.
Drag a List component from the Components panel to the Stage.
In the Property inspector, do the following:
Enter the instance name aList .
Assign a value of 200 to the W (width).
Use the Text tool to create a text field below aList and give it an instance name of aTf .
Open the Actions panel, select Frame 1 in the main Timeline, and enter the following ActionScript code:
import fl.controls.List;
import flash.text.TextField;
aTf.type = TextFieldType.DYNAMIC;
aTf.border = false;
// Create these items in the Property inspector when data and label
// parameters are available.
aList.addItem({label:"1956 Chevy (Cherry Red)", data:35000});
aList.addItem({label:"1966 Mustang (Classic)", data:27000});
aList.addItem({label:"1976 Volvo (Xcllnt Cond)", data:17000});
aList.allowMultipleSelection = true;
aList.addEventListener(Event.CHANGE, showData);
function showData(event:Event) {
aTf.text = "This car is priced at: $" + event.target.selectedItem.data;
}
This code uses the addItem() method to populate aList with three items, assigning each one a label value, which appears in the list, and a data value. When you select an item in the List, the event listener calls the showData() function, which displays the data value for the selected item.
Select Control > Test Movie to compile and run this application.
source: http://help.adobe.com/en_US/ActionScript/3.0_UsingComponentsAS3/WS5b3ccc516d4fbf351e63e3d118a9c65b32-7fa6.html
Finally i have got the answer from some other forum.
Here is the link to the example (behavior) that i want to add to my list :
http://www.learningactionscript3.com/2008/05/13/the-power-of-relative-positioning/
(at the bottom 'Advanced Align Example').

AS3 - Displaying points gained above the player

So, I am adding this text field to my container MC whenever a certain condition is met.
In this case, I am trying to display the number of points gained above a playerMC whenever he grabs a coin. Kind of like the old Mario Games whenever you would step on a Goomba and points would appear above the dead Goomba.
I'd like to be able to assign the "points" text field to a "Text.as" file so I could just control the text field's behaviors from there instead of from within my Document Class.
I know how to create a text field from the document class, but I can't seem to create an empty text field on the stage and then convert it into a movie clip so that I can assign it a base class.
Anyone know of a good way to handle this situation? Any ideas you might have.
It's most efficient to just create the textField via code in the contstructor of your Text.as class. However, if you're set on doing it in the flash IDE... create your dynamic text field, give it an instance name, then convert it to a MovieClip with F8. Go to the library and enter you're new movieClip's properties, set the base class to your Text.as file.
Your class (which encapsulates the textField) should then start out looking something like this:
package {
public class Text extends Sprite {
public var myTextFieldInstanceName:TextField;
public function set text(val:String):void { myTextFieldInstanceName.text = val; }
public function get text():String { return myTextFIeldInstanceName.text;}
public function Text(defaultText:String){
text = defaultText;
}
}
}
In order to set the base class, you need to do the same thing that I recommended you do for your Bullet and Impact movieclips. You perform a linkage by selecting "Export to Actionscript". You can tell it what class to look at for its behavior. Then just addChild it to your playerMC (after adjusting x and y values of course).