Dynamic text field in Frames not changing text in actionscript 3 - 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";

Related

Making a textField inside a movie clip display specific text after mouse click in actionscript 3

first of all let me clarify that I've been working with AS3 only for a couple of days. My project consists of a google map of a street which acts as a menu where the buttons are labels floating over some of the houses. The idea is that when you click on certain house a module of specific info spreads. That info would be textual and some photos. My intention is to have that module as a movie clip template that I create just once and would fill up dynamically with the info related with each clicked house. It's a long way to get to that and I still have to figure how to do it. But I'm starting with this little thing:
I want that when I click on certain button it tells a dynamic text field inside the movie clip to display the house address which acts as a tittle for the card where the info is displayed. I'm experimenting with currentTarget but despite not getting any errors the code is just not working. Here's my code:
z5990_btn.addEventListener(MouseEvent.CLICK,setTittle);
function setTittle(event:MouseEvent)
{
var target = event.currentTarget;
var tittle = houseCard_mc.tittle_txt;
tittle.text=String(target);
}
Please note that my learning consists basically of reading and asking forums and lots of trail and error. Thanks for taking time to read this and help me.
Trace tittle to make sure it's actual TextField:
//...
var tittle = houseCard_mc.tittle_txt;
trace("tittle is:", tittle, "currentText:", tittle.text);
tittle.text=String(target);
you should see this in output:
tittle is: [object TextField] currentText: foo
if it's not a TextField object but MovieClip then you will see this.
tittle is: [object MovieClip] currentText: undefined
Than means that you are creating new text field in your tittle MovieClip with string content, which of course does nothing.
All you need to do is read for instance THIS EXAMPLE

Actionscript 3 - how to capture data from one text area into another text area on a different frame

Basically i am trying to capture data in a text area which is input from an XML file and then a few frames later get the text from that text area into another text area.
i have tried using movietxt.text = txtarea.text;but that doesn't seem to work.
another ive used is:
txtarea.addEventListener(Event.CHANGE, changehandler);
function changehandler(evt:Event):void
{
movietxt.text = txtarea.text;
};
Does anyone know if this is possible and if so what is the code?
Does anyone know if this is possible and if so what is the code?
Yes, this is possible.
Store data in the frame where you capture text:
this.storedText = "some stored text";
Later, a few frames after, restore text:
movietxt.text = this.storedText;

How to copy Input Text Value into Dynamic Text that is in a MovieClip1 Inside a MovieClip2

Current my code is as such
setcustomlocation.addEventListener(MouseEvent.CLICK,customlocation2);
function customlocation2(e:MouseEvent):void
{
locationinput.text = FlashingWon.Won1.name.text;
}
I'm trying to make it such that it would copy the input text field values into a dynamic text. However, it throws up the error that
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at main/customlocation2()[main::frame1:9]
Which can I only assume that it is not able to communicate with the dynamic text field in the movieclip within another movieclip.
First, you can be 100% sure that it CAN communicate with the dynamic TextField in the MovieClip.
From you description I understand that you wish to copy from input into dynamic. But from your code I see that you take from the dynamic into the input, please check that out:
// This will copy in such a way: input <= wonText
locationinput.text = FlashingWon.Won1.name.text;
// This will copy from input
FlashingWon.Won1.name.text = locationinput.text;
Anyhow, the error that you get has nothing to do with this, it's rather like you already noticed, that one of your TextField is not 'found'. For this I recommend you a best practice: To create instances of the objects you want to use and populate them from the stage through the getChildByName method. This way you will promptly now (specially if you do this on construction or init) if you had any misspelling or miss structure on the childs you want to get.
like so:
var inputText: TextField;
var dynoText: TextField;
In your Constructor or else where at a soon level, give to your vars the proper value:
inputText = getChildByName('locationinput') as TextField;
dynoText = FlashingWon.Won1.getChildByName('name') as TextField;
This way you will soon enough know if one of this 2 textFields were not found under the object you give, and you have only one place to miss spell it. Also you will get code completion on your TextFields.
Finally the copy text part:
dynoText.text = inputText.text;
Hope it helps.
Alright, sorry for the delay, I was out on holidays.
I have opened your example and can see where the problems are:
1) You are trying to reach the FlashingWon when initiating the dynoText on the FIRST frame like so var dynoText = FlashingWon.Won1.getChildByName('name_txt'); BUT the FlashingWon element is ONLY available on the FIFTH frame. Meaning that you cannot refer to it quite yet, unless you add it on the first frame and make in invisible till the fifth frame. (You can make it visible in the goto1 function if you wish after the goToAndStop(5) line)
2) You called the TextField on the Won1 element 'name' which is a restricted sting in AS3, so change it to name_txt or label if you wish and it will work.
Let me know how it worked.

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).

Actionscript 2.0 and 3.0: Specific "text" in input box causes certain image to display

I want to know how(and what scripts) to take words from a text input box and cause it to display and image Ex: if the text box said "smiley face" in it, then the image "smiley_face.jpg" would display on a certain movieclip and can be dragged around the stage and when a new image is loaded, it doesn't replace the previous image on the movie clip.
You need to listen for the textInput event and you need to constantly search for "smile" using something like the search() function(u can use strings or regular expressions).
It returns -1 if the string you're searching for wasn't found, otherwise it returns the first index where the searched string was found.
Here's a really basic example:
var ti:TextField = new TextField();
ti.type = TextFieldType.INPUT;
ti.border = true;
addChild(ti);
ti.addEventListener(TextEvent.TEXT_INPUT, onInput);
function onInput(event:TextEvent):void {
if(ti.text.search('smile')!=-1) trace('display smiley image');
}
You did mention smileys, so depending on your level of comfort with actionscript 3, it might be also worth having a look at Thibault Imbert's SmileyRenderer. Careful it uses the new FTE so you need to use Flash Player 10, etc.
yeah. In ActionScript you need to add a listener event to the text field. then you can do something like this. My action script is not so good so I will just stick with logic.
if listener.text == "smile"
smile.jpg
else if listener.text == "frown"
frown.jpg
else
default.jpg
end
You should check out lynda.com for their basic AS screencasts