Delegate class??????
±¾ÎÄ×÷Õß:egoldy
ÎÄÕ³ö´¦:http://www.actionscript.org
ÎÄÕÂÐÔÖÊ:??
ÔĶÁ´ÎÊý:13494
·¢²¼Ê±¼ä:2005-06-11
??????????http://www.actionscript.org.????????????


Delegate class ??????


Delegate???? ????????????Mike Chambers??????????????????????????”Ellipsis”?????flashmx2004?????????????????????flashmx2004updata_cn.exe,????????Delegate????FLASH???????????

??????????????????????????????addEventListener ????????????????????????

????????
??????
´úÂë:

var obj = new Object();
obj.click = function(evt)
{
        trace(evt.target);
        trace(this);
}
myBtn.addEventListener("click",obj);


????????
´úÂë:

function myClickHander(evt){
    trace(evt.target);
    trace(this);
}
myBtn.addEventListener("click",myClickHander);


?????????????????????????????click??????????????????????????????????????????????
´úÂë:

obj = new Object();
obj.click = function(evt)
{
        if(evt.target == 'myBtn')
        {
                trace('first button');
        }
        if(evt.target == 'myBtn2')
        {
                trace('second button');
        }
}
myBtn.addEventListener("click",obj);
myBtn2.addEventListener("click",obj);



?????????????“this”?????????????????????????????????????????”this”??????????????????????????????????????????

Mike Chambers?????????????????????????????Delegate ????????????????????delegate ?????????????????????????????????????????????
´úÂë:

import mx.utils.Delegate;
function myClickHandler(evt)
{
        trace(evt.target);
        trace(this);
}
myBtn.addEventListener("click", Delegate.create(this,myClickHandler));


??????????delegate ????mx.utils.Delegate??????????????????Delegate??????????????Delegate?????????????create,?????????
´úÂë:

static function create(obj:Object, func:Function):Function


???????obj???????func????????????????????????????
´úÂë:

import mx.utils.Delegate;
var md = Delegate.create(this, someFunction);
myBtn.addEventListener('click',md);
//????
//????
myBtn.removeEventListener('click',md);


???????Delegate.create????????????????????????jess warden??????Delegate ??????????

Delegate????????????????????????????movieclip’s onEnterFrame?????xml???onLoad??????
´úÂë:

import mx.utils.Delegate;

function xmlLoaded(success)
{
        trace(this);
        trace(success);
}

function handleEnterFrame()
{
        trace(this);
        trace(getTimer());
}

var myXML = new XML();
myXML.onLoad = Delegate.create(this, xmlLoaded);
myXML.load(“some.xml”);

//myMc???????????
myMC.onEnterFrame = Delegate.create(this, handleEnterFrame);


????Delegate?????????????????????????????????????????_root.

?????Delegate???????setInterval????????????????????????????????????????trace(this);????undefined.????????????????????
´úÂë:

import mx.utils.Delegate;

function traceThis()
{
        trace(this);
}

var myInt = setInterval(Delegate.create(this, traceThis), 1000);



??????????????????????????????????setInterval????string??????????????FLASH???????????????setinterval????????????????????????????????????????????????????????string????

????????Delegate.create?this??????????99%????????????????????????????Delegatey????????????this.Delegate???????????????


?????


   
 
Copyright (C) 2004 websudio Team All Rights Reserved.