Thanks leds,
really helpful!

Additionally, the default hitarea is sprite itself. "cmt.hitArea= cmt;" can be 
omitted.
^ ^

----- 原始邮件 ----
发件人: leds usop <[EMAIL PROTECTED]>
收件人: [email protected]
已发送: 2007/3/4(周日), 下午8:45:09
主题: Re: [flexcoders] Re: How does sprite listener work?

the modal alert window causes your problem. When the
modal Alert activates, it 'forces' your mouse to leave
that sprite and hence making it think that a mouse
rollOUT event took place. try this to verify:

<?xml version="1.0" encoding="utf- 8"?>
<mx:Application
xmlns:mx="http://www.adobe. com/2006/ mxml"
layout="vertical" >
<mx:Script>

<![CDATA[
import mx.controls. Alert;

private function mouseDoubleClickLis tener
(event:MouseEvent) :void
{

var cmt:Sprite=new Sprite();

cmt.graphics. lineStyle
(2,0x000000, 1);
cmt.graphics. beginFill
(0xff0000,1) ;
cmt.graphics. drawCircle( event.localX, event.localY,
10);

cmt.graphics. endFill() ;
a.rawChildren. addChild( cmt);
cmt.hitArea= cmt;
cmt.addEventListene r(MouseEvent. ROLL_OVER,
mouseOverListener) ;
cmt.addEventListene r(MouseEvent. ROLL_OUT,
mouseOutListener) ;
b.mouseEnabled= false;
//}
}

private var ctr:int=0;

private function mouseOverListener
(event:MouseEvent) :void
{ 
testtext.text= "rollover: " +ctr.toString( );
ctr++;

}

private function mouseOutListener
(event:MouseEvent) :void
{

testtext.text= " rollout: " +ctr.toString( );
ctr++;
}

]]>
</mx:Script>
<mx:Panel id="a" mouseEnabled= "false">
<mx:Canvas id="b" width="474" height="471" 
doubleClick= "mouseDoubleClic kListener( event)"
doubleClickEnabled= "true"/>
</mx:Panel>
<mx:Text id="testtext" text="Text"/ >
</mx:Application>

You will see that the counter only increments once for
every mouseover and mouse out.

Cheers,
-leds

--- Sandwish <sandwish_mx@ yahoo.com. cn> wrote:

> Thanks,Gordon!
> 
> <?xml version="1.0" encoding="utf- 8"?>
> <mx:Application
> xmlns:mx="http://www.adobe. com/2006/ mxml" 
> layout="vertical" >
> <mx:Script>
> <![CDATA[
> import mx.controls. Alert;
> 
> private function mouseDoubleClickLis tener
> (event:MouseEvent) :void
> {
> 
> var cmt:Sprite=new 
> Sprite();
> 
> cmt.graphics. lineStyle
> (2,0x000000, 1);
> cmt.graphics. beginFill
> (0xff0000,1) ;
> cmt.graphics. drawCircle
> (event.localX, event.localY, 10); 
> 
> cmt.graphics. endFill() ;
> a.rawChildren. addChild
> (cmt);
> cmt.addEventListene r
> (MouseEvent. ROLL_OVER, mouseOverListener) ;
> cmt.addEventListene r
> (MouseEvent. ROLL_OUT, mouseOutListener) ;
> //}
> }
> 
> private function mouseOverListener
> (event:MouseEvent) :void 
> { 
> Alert.show(" rollover" );
> 
> }
> 
> private function mouseOutListener
> (event:MouseEvent) :void 
> { 
> Alert.show(" rollout") ;
> }
> 
> ]]>
> </mx:Script>
> <mx:Panel id="a">
> <mx:Canvas id="b" width="500" height="500" 
> doubleClick= "mouseDoubleClic kListener( event)" 
> doubleClickEnabled= "true"/>
> </mx:Panel>
> </mx:Application>
> 
> Run the code and the problem is obvious.
> 
> Regards.
> 
> --- In [EMAIL PROTECTED] ups.com, "Gordon Smith"
> <[EMAIL PROTECTED] > wrote:
> >
> > It's not obvious to me why that would be
> happening. Can you post 
> the
> > code for a simple app which demonstrates the
> problem?
> > 
> > - Gordon
> > 
> > ____________ _________ _________ __
> > 
> > From: [EMAIL PROTECTED] ups.com 
> [mailto:[EMAIL PROTECTED] ups.com] On
> > Behalf Of Sandwish
> > Sent: Tuesday, February 27, 2007 11:22 AM
> > To: [EMAIL PROTECTED] ups.com
> > Subject: [flexcoders] How does sprite listener
> work?
> > 
> > 
> > 
> > I new a sprite and addeventlistener which listens
> roll_over and
> > roll_out event. But after a circle is drawn with
> beginfill and
> > endfill, each time I roll inside the circle, both
> events get 
> invoked.
> > I don't know why? :(
> > 
> > Thanks in advance!
> > Regards,
> > Sand
> >
> 
> 
> 

____________ _________ _________ _________ _________ _________ _
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.
http://new.mail. yahoo.com




                
___________________________________________________________ 
雅虎免费邮箱-3.5G容量,20M附件 
http://cn.mail.yahoo.com/

Reply via email to