A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Scoping and Dynamic Event Handler Creation

  1. #1
    ActionScript.org
    Join Date
    Aug 2000
    Posts
    1,030
    I came accross this problem in someone else's post today. They could use a workaround. I cannot. Checkout the following code )simplified example):
    Code:
    Object.prototype.setButton = function() {
    	trace(this.name);
    	tmp.onPress = function() {
    		trace(this.name);
    	};
    };
    myAr = {name:"John"};
    myAr.setButton();
    I have a button on the stage with instance name 'tmp'.

    I need some help figuring out how to make the onPress function spit out the name property of the Object which created the handler. At present the 'this.name' in the handler ends up referring to the MovieClip, not the object! I understand why, but I dont understand how to make it do what I want. I'm not too good at al this in depth OO stuff. Any help?

  2. #2
    Master Poo Flinger
    Join Date
    Sep 2000
    Posts
    318
    i'm not exactly sure if i understand your problem.

    is "tmp" the name of an object created with the MovieClip constructor?

    if tmp is a MovieClip and you want the name of myAr to be traced when tmp is pressed:
    Code:
    Object.prototype.setButton = function ()
    {
    	//trace (this.name);
    	tmp.traceName = this.name;
    	tmp.onPress = function ()
    	{
    		trace (this.traceName);
    	};
    };
    myAr = {name:"John"};
    myAr.setButton ();
    hope this helps

  3. #3
    ActionScript.org
    Join Date
    Aug 2000
    Posts
    1,030
    One day I'll learn not to program at 4am Cheers very much.

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