Accessing instance from symbol class - actionscript-3

I have created a text field with the type "Input text" and put the instance name to NameInput. I have also created a MovieClip symbol which works like a button. Basically, I want to trace what text/input NameInput has from the button class.
trace(NameInput.x) does not work and shows the error "1120: Access of undefined property NameInput."
How can I access the instance NameInput from the button class?

When you say trace(NameInput.x), ActionScript looks for an object within your button with that name, and doesn't find it. You might be able to try
var nameInput = MovieClip(this.parent).getChildByName('NameInput');

Related

Edge Animate - How can i access and change a text from a button in different symbols?

I have this:
ELEMENTS:
Stage - symbol_1
- symbol_2
So,... i would like to change a text inside symbol_2 from a button on symbol_1, using sym.$("Text").html("NewText"); What's the correct path!?
In the click event of symbol_1 -> button write this:
var stage = sym.getParentSymbol();
var sym2 = stage.getSymbol("symbol_2");
sym2.$("Text").html("NewText");
This code works if both symbol_1 and symbol_2 are children of Stage.
Please note that symbol_1 and symbol_2 are the instances names of the symbols, as they appear in the "Elements" panel (not in the symbol library)

Change text from other class with AS3?

I have some action script in the first layer and it imports a CustomSocket class from an external .as file. When I receive a command on the socket I want to edit the GUI objects. For example, when I get the command TIME 23 from the server I want to change the dynamic text box timerBox to the value 23. I have a method called processCommand(cmd:String) in the CustomSocket class, but I don't know how to change the text. Usually you can just do timerBox.text = "23"; but this doesn't work in an external class?
If 'CustomSocket' is not your document class, then you need to specify some reference for your timeline in your class.
For general example,
While importing a class,
import CustomSocket;
csObj:CustomSocket = new CustomSocket(this);
then, inside class, in constructor
public function LibraryS(_ref:Object):void
{
timelineRef = _ref;
}
then in your class you can say,
timelineRef.timeBox.text = "23";

actionscript 3 event.target

I have a movie clip named button1 and in this movie clip
there is a dynamic text named txt
public function mouse_down(event:MouseEvent)
{
if(event.target==button1)
{
...//this only recognizes when i click the button without intersecting the dynamic text area
}
if(event.target==button1||event.target==button1.txt)
{
...//this works
}
i would like to know why it dosen't recognize clicks made in the area that contains the dynamic click if i don't specify it, because txt is part of button1, so normally i would only need to check if the target is button1 but it dosen't work:i also have to check if the target is button1.txt
Thanks for your help!
event.target always points to the object the event originated from, even if it is nested in the object you added the listener to. Use event.currentTarget instead.
Check out this blog post to learn more.

AS3 call a just added element

i'm adding a movieclip element ("lastSlide") to an other movieclip element("endLogoButton"). The added element has a child which is a button("endLogoButton"). How can i call that button?
mcSlideHolder.addChild(lastSlide);
/*mcSlideHolder.getChildByName("endLogoButton").buttonMode = true;;
mcSlideHolder.getChildByName("endLogoButton").mouseChildren = false;
mcSlideHolder.getChildByName("endLogoButton").useHandCursor = true;*/
lastSlide.endLogoButton.addEventListener(MouseEvent.CLICK, linkClick);
As a beginner i'm struggling around ... but can't make it work ...
It always tells me that the access to a Nullobject reference is not possible.
Thanks for any advice!
You can either 'dig in' to the nested objects to get to the button instance or you can add event listeners to the button instance before adding it to its parent container then let its click event bubble up.
I'm having a bit of trouble understanding what is nested inside of what in your case but I see you're trying getChildByName. getChildByName only gets a direct child (not a child of a child) by its instance name, (not it's variable name).
Dig in example:
lastSlide.getChildByName("endLogoButton").addEventListener(MouseEvent.CLICK, linkClick);
or
lastSlide.name = "myLastSlide";
mcSlideHolder.getChildByName("myLastSlide").getChildByName("endLogoButton").addEventListener(MouseEvent.CLICK, linkClick);
If lastSlide were placed on the stage visually in the Flash IDE, then you could set the instance name myLastSlide there in the properties panel rather than by setting the name property in as3.
or maybe: try casting the "lastSlide" to a MovieClip like:
MovieClip(mcSlideHolder.getChildByName("lastSlide")).getChildByName("endLogoButton").addEventListener(MouseEvent.CLICK, linkClick);
This worked for me several times when the "possible unreferenced object" error popped up when referencing a movieclip that was clearly added to the stage

error called to undifined method when using pop()

I'm trying to add the pop function to a button in flex 4. But I keep getting an error call to undefined method when I try to use it, but it's a built in function isn't it? I posted my code below, any ideas?
<s:Button x="405" y="410" label="Undo last" width="85" click="data.pop()" id="undo"/>
data.pop() most likely won't work unless you are using your button as item renderer or item editor in a DataGrid.
In case you defined a variable of type Array called data try to rename it to something else. data is used by the framework itself.