Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript 3.0 (http://www.flasher.ru/forum/forumdisplay.php?f=83)
-   -   Как работает getObjectsUnderPoint? (http://www.flasher.ru/forum/showthread.php?t=211196)

undefined 11.07.2015 02:30

Как работает getObjectsUnderPoint?
 
Читаем хэлп:
Цитата:

Returns an array of objects that lie under the specified point and are children (or grandchildren, and so on) of this DisplayObjectContainer instance. Any child objects that are inaccessible for security reasons are omitted from the returned array. To determine whether this security restriction affects the returned array, call the areInaccessibleObjectsUnderPoint() method.
Т.е. возвращать он должен детей,так?Пишу
Код AS3:

var objs:Array = cont.getObjectsUnderPoint(new Point(stage.mouseX, stage.mouseY));
trace(objs[0]==cont); //true

Самое интересное, что в objs вообще нет того, над чем мышь находится

caseyryan 11.07.2015 10:01

так а почему ты пишешь stage.mouseX, а не cont.mouseX?

undefined 11.07.2015 16:37

Цитата:

так а почему ты пишешь stage.mouseX, а не cont.mouseX?
потому что
Цитата:

The point parameter is in the coordinate space of the Stage, which may differ from the coordinate space of the display object container (unless the display object container is the Stage). You can use the globalToLocal() and the localToGlobal() methods to convert points between these coordinate spaces.
Я, кажется, понял в чем дело - похоже он возвращает список DisplayObject'ов, а не DisplayObjectContainer'ов.
Если делать так
Код AS3:

stage.getObjectsUnderPoint(new Point(stage.mouseX, stage.mouseY));

и перебирать родителей того что вернулось - можно найти компонент, над которым висит мыша.
При этом уже
Код AS3:

trace(objs[0]==stage);//false

Как в результат попадает контейнер, у которого был вызван этот метод - загадка

callme 12.07.2015 12:34

Если в контейнере лежит битмапа, то вернется битмапа. Если в контейнере лежит спрайт, на котором ты что-то нарисовал (sprite.graphics), то вернется спрайт.

А если нарисуешь что-то на самом контейнере, то ребенка не будет, поэтому возвращается сам контейнер.


Часовой пояс GMT +4, время: 23:11.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.