A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: understanding parent/child classes vs nested symbols and accessing their variables

  1. #1
    Junior Member
    Join Date
    Oct 2008
    Posts
    4

    understanding parent/child classes vs nested symbols and accessing their variables

    G'day, this problem has been doing my head in for the last 2 days. I've got a button and two text fields located inside a loginBox movieClip which is linked to the class loginBox. The textfields are named username and password. The button is called loginBoxButton and when it is pressed all I want it to do at this stage is trace the value of username and password. Later I'll be sending data over a XMLSocket to a python backend.

    My code looks like this:

    Code:
    package 
    {
    	import flash.display.SimpleButton;
    	import flash.events.MouseEvent; 
    	import flash.text.TextField;
    	import loginBox;
    	public class loginBoxButton extends SimpleButton
    	{
    		public function loginBoxButton()
    		{
    			this.addEventListener(MouseEvent.CLICK, clickHandler);
    		}
    		public function clickHandler(event:MouseEvent):void {
    	    trace("clickHandler detected an event of type: " + event.type); 
        	trace("the event occurred on: " + event.target.name);
    		trace(loginBox.username);
    		}
    	}
    }
    which throws up 1119: Access of possibly undefined property username through a reference with static type Class. on the trace(loginBox.username); line.
    I've also tried

    trace(this.parent.username);

    which gives me this: 1119: Access of possibly undefined property username through a reference with static type flash.displayisplayObjectContainer.

    which after some thought brought me to the conclusion I was confusing class inheritance with nesting objects inside each other.

    So looking through the documentation on DisplayObjectContainner I though loginBox should act as a container for the 2 textfields and the login button but when i tried trace(loginBox.getChildByName("username")); It threw back

    1061: Call to a possibly undefined method getChildByName through a reference with static type Class.

    Which was a similar error to the first one.


    At this point I'm completely stuck, and stuck because I don't understand how flash's implementation of object orientated programming works (although I have done a lot of c++ OO work), or how it nested stage objects should be accessed within code. Also, and this is a more basic question, was i right in assuming everything on stage if exported / given a name has a corresponding class in code.



    Any help very, very, very much appericated

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    assuming username is the instance name of your username text field, you won't be able to access it by looking in the loginBox class file. That's only possible when looking up static variables or methods.

    Without knowing how or when the loginBox instance is being created it's tough to say how loginBoxButton instances can access its children (ie. username and password)

    Assuming loginBoxButton, username and password are all children of loginBox, the button will need to treat the text fields as siblings meaning you would have to start by referencing the parent and then the textfield.

    try:

    trace(parent.username);

    On an unrelated note. Class files are normally spelled with a capital letter to help differentiate object and properties.

    myClassInstance:MyClass = new MyClass();

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center