🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: alt.pl.programy.flash-5
1 messages
1 total messages Started by Devoth Sun, 16 Dec 2007 14:11
[AS 3] własny kursor i przechwytywanie kliknięć na przyciskach
#34428
Author: 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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads