To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 02-14-2006, 09:23 PM   #1
flashDeveloper
Junior Member
 
Join Date: Jan 2003
Posts: 6
Delegate.Create for an mc inside a class [DEADLINE] pls help

PHP Code:
import mx.events.EventDispatcher;
import mx.utils.Delegate;

class
main_movie extends MovieClip
{
    public var
pbSend:Button;
    public var
my_mc:MovieClip;
    public var
my_button:MovieClip;

    
// constructor
    
public function main_movie()
    {
        
super();
        
EventDispatcher.initialize(this);
        
my_mc = attachMovie ("my_mc", "my_mc", getNextHighestDepth(), {_x :100, _y:50} );
        
my_button = attachMovie ("my_button", "my_button", getNextHighestDepth(), {_x :100, _y:50} );
        
my_button._x = 100;

        
// I want to avoid doing this function here..
        /*this.onLoad = function()
        {
            // this is the only line that works and it does add the event.
            pbSend.addEventListener("click", Delegate.create(this, checkFields));

            // doesn't work
            my_mc.addEventListener("onRelease", Delegate.create(this, checkFields));

            // doesn't work
            my_button.addEventListener("onRelease", Delegate.create(this, checkFields));
        }*/


        //this["my_mc"].addEventListener("click", Delegate.create(this, checkFields));
    
}

    
// I would rather do it here...
    
private function onLoad ()
    {
        
// doesn't work, this line doesn't work in the onLoad function if its placed here !
        //pbSend.addEventListener("click", Delegate.create(this, checkFields));

        // doesn't work This is the most important one I really need to get it to work
        
my_mc.addEventListener("onRelease", Delegate.create(this, checkFields));

        
// doesn't work
        
my_button.addEventListener("onRelease", Delegate.create(this, checkFields));
    }

    private function
checkFields():Void
    
{
            
trace("check");
    }
}

Hi I need help, all I want to do is to create an onRelease event for the my_mc
clip which is being attached within the main_movie class.

it works for the button component but not for the mc clip... please advice

thanks
Attached Files
File Type: fla sample.fla (164.5 KB, 6 views)
flashDeveloper is offline   Reply With Quote
Old 02-15-2006, 06:47 AM   #2
Lexicon
Monkey Moderator
 
Lexicon's Avatar
 
Join Date: Jul 2001
Location: UK
Posts: 2,038
Hi,

There is no need for the EventDispatcher. You just assign the function to the relevant onRelease properties.

Code:
import mx.utils.Delegate;

class main_movie extends MovieClip
{
    public var pbSend:Button;
    public var my_mc:MovieClip;
    public var my_button:MovieClip;

    // constructor
    public function main_movie()
    {
        my_mc = attachMovie ("my_mc", "my_mc", getNextHighestDepth(), {_x :100, _y:50} );
        my_button = attachMovie ("my_button", "my_button", getNextHighestDepth(), {_x :100, _y:50} );
        my_button._x = 100;
    }

    // I would rather do it here...
    private function onLoad ()
    {
        my_mc.onRelease = my_button.onRelease = Delegate.create(this, checkFields);
    }

    private function checkFields():Void
    {
            trace("check");
    }
}
__________________
www.lexicon-design.co.uk
If we aren't supposed to eat animals, then why are they made of meat?
If Vegetarians like animals so much, why do they eat all their food?
Lexicon is offline   Reply With Quote
Old 02-16-2006, 12:44 AM   #3
flashDeveloper
Junior Member
 
Join Date: Jan 2003
Posts: 6
Thank you for your help
flashDeveloper is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:11 PM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.