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.
Related
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
Can someone tell me how to dynamically change the button label during run time?
Here is the code i tried:
var go:Button = new Button();
go = symbol_1;
go.label = "GO";
This does not seem to work.
The error stated is "Access of possibly undefined property label through a reference with static type flash.display:SimpleButton"
First of all, you're doing it the wrong way. If you say var go:Button = new Button(); you create a new Button object and then assign another object to go variable. So the new Button you created has been lost, there are no references to it, therefore there is no need to create a new Button in this situation.
Second, your symbol_1 is of type SimpleButton as it's clear from the error. SimpleButton objects do not have label property, that's why you're getting an error when trying to assign to it.
Now for the workaround. You can either place a TextField in your symbol_1 and give it an instance name, which you will then reference like this:
// assuming that instance name for the placed TextField is 'textBox'
symbol_1.textBox.text = "new label";
EDIT: Actually go for the second method described below as this first one is buggy and not dependable.
Or I'd recommend you make your own class based on a MovieClip which has a label property and can change it without much hassle.
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";
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.
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).