AS3 Load library movie based on parameter on Parent - actionscript-3

I have following scenario:
I have created a movie symbol at library called mov_Child. Which has dynamic text field. But I have to pass parent movies text value to the mov_Child's dynamic text field.
How can I do that?

Give instance name to dynamic textfield e.g. "myTextField"
var parentMoviesText:String = "This is parent movies text";
mov_Child.myTextField.text = parentMoviesText; // Here you pass the text value

Related

cant access text field inside movieclip

I have a movie clip symbol that I converted from a dynamic text field with the instance name "text2". When I try to add it as a child and then try to access the text field, the compiler throws:
Error #1009: Cannot access a property or method of a null object reference.
var test = new Qwe(); //Qwe is the movie clip converted from dynamic text field
addChild(test);
test.text2.text ="535"; //instance name of the text field was text2.
The culprit was the "advanced layers" setting in Adobe Animate. Turning it off, solved the problem.

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";

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

textfield.text not showing every characters

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.