🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.pl.programy.flash-5
Article #34428

[AS 3] własny kursor i przechwytywanie kliknięć na przyciskach

#34428
From: Devoth
Date: Sun, 16 Dec 2007 14:11
72 lines
3482 bytes
Witam wszystkich, kopę lat ;)

Staram się zaktualizować swoją wiedzę o Flashu i AS 3. Przerabiam sobie 
właśnie bardzo ciekawy tutorial dostępny na 
http://movielibrary.lynda.com/html/modPage.asp?ID=366 pt "Creating a 
Shooter Game" i natrafiłem na pewną "zagwozdkę".

Otóż Autor w filmiku pt "Creating a custom cursor", stwierdza rzecz 
następującą:
cursor.enabled = false;
"What it will do - it will disable any mouse interactivity for the 
cursor. That way, when we use our mouse to click on Monsters on the 
screen to shoot them, Flash won't think we're clicking on the cursor, 
but rather Flash will know we're clicking on the monsters."

W przykładzie pokazywanym przez Autora to działa, ale jak się okazuje 
tylko dlatego że custom cursor jest dziurawy, jeżeli weźmiemy wypełniony 
kształt + centrowanie kursora - nie da się na nic kliknąć.

Napisałem sobie własny kawałek :
[AS 3.0]
function initializeGameEnviroment():void {
	cursor = new Cursor();
	addChild(cursor);
	cursor.enabled = false;
	Mouse.hide();
	stage.addEventListener(MouseEvent.MOUSE_MOVE, dragCursor);

	btn_startgame.addEventListener(MouseEvent.CLICK, startGame);

}
function dragCursor(event:MouseEvent):void {
	cursor.x = this.mouseX - cursor.width/2;
	cursor.y = this.mouseY - cursor.height/2;
}
function startGame(event:MouseEvent):void {
	var main:MovieClip = MovieClip (this);
	main.gotoAndStop('theGame');
}
[/AS 3.0]

Gdzie 'btn_startgame' jest zwykłym MC zawierającym prostokąt. Teraz 
jeżeli używam wypełnionego kursora - nie działa przejście do 'theGame', 
jeżeli usunę środek z kursora - działa.

Co mówi o tym help:
[help]
enabled property

enabled:Boolean  [read-write]

Language version:  ActionScript 3.0
Player version:  Flash Player 9

A Boolean value that indicates whether a movie clip is enabled. The 
default value of enabled is true. If enabled is set to false, the movie 
clip's Over, Down, and Up frames are disabled. The movie clip continues 
to receive events (for example, mouseDown, mouseUp, keyDown, and keyUp).
[/help]

... wychodzi że Autor wymyślił sobie ten brak interaktywności bo 
wyraźnie pisze że obiekt dalej otrzymuje eventy, a tylko wyłaczane są 
jego "button frames" i ta linijka (cursor.enabled=false;) dla pustego 
kursora jest zupełni niepotrzebna.

Tu moje pytanie - jak poprawnie po AS 3 -owemu sprawić żeby móc używać 
własny kursor (dowolny, w tym także wypełniony) i aby była możliwość 
przechwytywania eventów na obiektach na które się kliknie itd?

Pozdrawiam
Devoth
www.devoth.pl
Technical Details
Message-ID: <fk3bme$jg2$1@news.lublin.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!feed.news.interia.pl!news.nask.pl!news.nask.org.pl!lublin.pl!news.lublin.pl!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!feed.news.interia.pl!news.nask.pl!news.nask.org.pl!lublin.pl!news.lublin.pl!not-for-mail
From: Devoth <mail.na.www.devoth.pl@onet.pl>
Newsgroups: alt.pl.programy.flash-5
Subject: [AS 3] własny kursor i przechwytywanie
 kliknięć na przyciskach
Date: Sun, 16 Dec 2007 15:11:26 +0100
Organization: lubman
Lines: 72
Message-ID: <fk3bme$jg2$1@news.lublin.pl>
NNTP-Posting-Host: host-86-63-141-253.pronet.lublin.pl
Mime-Version: 1.0
X-Trace: news.lublin.pl 1197814286 19970 86.63.141.253 (16 Dec 2007 14:11:26 GMT)
X-Complaints-To: abuse@news.lublin.pl
NNTP-Posting-Date: Sun, 16 Dec 2007 14:11:26 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.9 (Windows/20071031)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit