svKris
svKris

Reputation: 793

Accessing class members

I have a class ABC:

class ABC
{
    var l:Label=new Label();
    var m:MovieClip=new MovieClip();
}

Given an instance of class ABC, e.g. obj:

var obj:ABC=new ABC();

I need to access both obj.m and obj.l. Say m has an eventlistener fl_listen which gets triggered on a mouse click:

function fl_listen(event:MouseEvent):void
{ 
   var k=event.target;
}

Within this handler, I can access the MovieClip of ABC class. However, my requirement demands to access the object of Label in the ABC class too. Any help will be greatly appreciated, I am rather new to using ActionScript.

Upvotes: 1

Views: 106

Answers (1)

goliatone
goliatone

Reputation: 2174

I think you should reconsider your architecture. Why do you have to handle the event in m? Just listen for the events inside of ABC and handle the event there, you have access to both the label and movieclip. If you need to perform some logic inside the movieclip instance m, then handle that and only that in your mc.

Using your pseudo code:

public class ABC
{

    var l:Label=new Label();
    var m:MovieClip=new MovieClip();

    function ABC(){
       m.addEventListener(MouseEvent.X,_handleX );
    }

    private function _handleX(e:Event):void{
       //you have access to both. Do what you need:
       m.alpha = 0.4;
       l.text = 'Changed';
    }


}

Upvotes: 1

Related Questions