Smart9Slice

Smart9Slice is a small class for better handling 9-slice scaling in flash.
It allows you to “duplicate” visual object parts instead of scaling. Check the example below (click somewhere on the flash object).

Smart9Slice — это небольшой класс для лучшего использования 9-slice scaling во флэше.
Он позволяет “дублировать” части визуального объекта вместо растягивания. Пример внизу (тыкайте по флэш объекту).

You can find the sources at Google Code.

How to Use

There are 2 versions of the class: Smart9Slice and AnimatedSmart9Slice. Both take their sub-object visuals from stage during creation, but unlike Smart9Slice which takes a snapshot of the first frame, AnimatedSmart9Slice stores MovieClips (which can be animated and can have mouse events) and duplicates them when needed.

Smart9Slice

You can created the objects of this class only in Flash IDE and use them in a SWF or SWC. To do that in linkage properties set base class of your object to ru.valyard.smart9slice.Smart9Slice, check Enable guides for 9-slice scaling checkbox, adjust these guides and voila, your object is set up.

Another way is to manually create 9 parts of your object, put them on stage (uncheck the 9-slice checkbox) and call them with the following names: tl, t, tr, l, c, r, bl, b, br, where t means top, b means bottom, r means right and l means left. You can also use “_” after the name (like “tl_”) which indicates that this part should be scaled not duplicated. These objects will be used for constructing of a Smart9Slice object and can’t be animated or have mouse events on them.

AnimatedSmart9Slice

AnimatedSmart9Slice can be configured only with the second way described earlier. But at this time object parts can have animation inside and can respond to mouse events. They are duplicated when needed. For this to work you must(!) specify a linkage identifier for each part on stage in its properties.

Advanced

You don’t need to have all 9 objects on stage if you are creating your Smart9Slice object from sub-objects. Actually, you can have zero objects but why would you need it?

Smart9Slice takes width and height from stage and sub-objects’ width and height from their width and height properties. But sometimes (for example when masks are involved) you want to specify them manually. For this purpose you can create an invisible Sprite called vMask or visibilityMask in your object or its parts and width + height will be taken from it.

Использование

Есть две версии класса: Smart9Slice и AnimatedSmart9Slice. Обе опираются на то, что было на сцене во время создания, но в отличие от Smart9Slice, который делает “снимок” кадра, AnimatedSmart9Slice хранит MovieClip’ы (которые могут быть анимированными и отвечать на события мыши) и размножает их когда нужно.

Smart9Slice

Вы можете создать объекты этого класса только во Flash IDE и скомпилировать их в SWF или SWC. Для того, чтобы это сделать поставьте в свойствах linkage вашему объекту в ru.valyard.smart9slice.Smart9Slice, включите чекбокс Enable guides for 9-slice scaling, настройте линейки как вам удобно и вуаля, объект готов к работе.

Другой способ — это вручную положить на сцену в объект 9 его частей (при этому нужно выключить чекбокс 9-slice) и назвать их следующими именами: tl, t, tr, l, c, r, bl, b, br, где t значит верхний, b — нижний, r — правый, l — левый. Также, вы можете добавить “_” к названию (например “tl_”), что означает, что этот элемент нужно скейлить вместо дуплицирования. Эти объекты будут использованы при создании объекта класс Smart9Scale и не могут быть анимированы или отвечать на события мыши.

AnimatedSmart9Slice

AnimatedSmart9Slice может быть сконфигурирован только вторым способом описанным выше. Но при этом части объекта могут быть анимированы и могут отвечать на события мыши. Они дублируются по необходимости. Чтобы это работало вым необходимо(!) выставить имя в свойствах linkage для каждого маленького объекта.

Advanced

Не обязательно создавать все 9 подобъектов. Вообще, можно не создавать ни одного, но зачем это нужно?

Smart9Slice берет ширину и высоту с самого себя и со свойств width и height подобъектов. Но иногда (например, когда дело доходит до масок) появляется необходимость вручную выставить эти параметры. Для этого вы можете создать невидимый Sprite с именем vMask или visibilityMask в своем объекте или его частях, с которого и будут браться ширина и высота.

Tags: , ,

Leave a Reply