Skip to content

Commit c2fb973

Browse files
author
as
committed
-added MovieClipButton.as
1 parent 23a9a73 commit c2fb973

File tree

6 files changed

+160
-5
lines changed

6 files changed

+160
-5
lines changed

.flexLibProperties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<classEntry path="com.hendrix.feathers.controls.flex.flexTabBar.FlexTabBar"/>
5959
<classEntry path="com.hendrix.feathers.controls.textService.BidiTextField.bidi.core.DirectionalOverrideStatus"/>
6060
<classEntry path="com.hendrix.feathers.controls.utils.SAppUtils"/>
61+
<classEntry path="com.hendrix.feathers.controls.flex.MovieClipButton"/>
6162
</includeClasses>
6263
<includeResources/>
6364
<namespaceManifests/>

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ public function startSplash(flashSpriteParent:flash.display.DisplayObjectContain
189189
layout options. great for dynamic splash screens
190190
* `BidiTextField` Bidirectional Text field with *bitmap fonts*. based on another repository i have published
191191
* `TLFLabel` Bidirectional Image text label based on `Adobe TLF`.
192+
* `HitButton` a flex button with a definable Polygon hit area.
193+
* `DragHitButton` a draggable button with ability to register objects for drop on and events.
194+
* `MovieClipButton` a flex button with `MovieClip` skin and sound and events.
192195

193196
- a set of widgets
194197
* `ListUpdateWidget` - a widget that hooks to a list to augment it with pull to refresh feature.

bin/Falcon.swc

5.92 KB
Binary file not shown.

src/com/hendrix/feathers/controls/flex/FlexButton.as

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ package com.hendrix.feathers.controls.flex
5858
public function FlexButton()
5959
{
6060
super();
61+
62+
_isToggle = false;
6163
}
6264

6365
/**
@@ -279,7 +281,7 @@ package com.hendrix.feathers.controls.flex
279281
_relativeCalcWidthParent = null;
280282
_relativeCalcHeightParent = null;
281283
}
282-
284+
283285
override protected function initialize():void
284286
{
285287
super.initialize();
@@ -296,7 +298,7 @@ package com.hendrix.feathers.controls.flex
296298
}
297299
}
298300
}
299-
301+
300302
protected function setupSize():void
301303
{
302304
var arIcon: Number;
@@ -392,7 +394,7 @@ package com.hendrix.feathers.controls.flex
392394
}
393395

394396
}
395-
397+
396398
override protected function draw():void
397399
{
398400
var sizeInvalid: Boolean = isInvalid(INVALIDATION_FLAG_SIZE);
@@ -407,7 +409,7 @@ package com.hendrix.feathers.controls.flex
407409

408410
super.draw();
409411
}
410-
412+
411413
private function getValidAncestorHeight():DisplayObject
412414
{
413415
var validParent: DisplayObject = parent;

src/com/hendrix/feathers/controls/flex/FlexImage.as

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ package com.hendrix.feathers.controls.flex
7878

7979
/**
8080
* source can be anything<br>
81-
* bitmap class, bitmapdata, bitmap, GfxPackage path, local path
81+
* <code>Texture, bitmap class, bitmapdata, bitmap, GfxPackage path, local path</code>
8282
*/
8383
public function get source():Object { return _source; }
8484
public function set source(value:Object):void
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
package com.hendrix.feathers.controls.flex
2+
{
3+
4+
import flash.media.Sound;
5+
import flash.utils.getQualifiedClassName;
6+
7+
import starling.core.Starling;
8+
import starling.display.DisplayObject;
9+
import starling.display.MovieClip;
10+
import starling.events.Event;
11+
import starling.events.Touch;
12+
import starling.events.TouchEvent;
13+
import starling.events.TouchPhase;
14+
15+
/**
16+
* a <code>Button</code> with a <code>MovieClip</code> skin.
17+
*
18+
* <lu>
19+
* <li/>you can listen to <code>MovieClipButton.ANIMATION_FINISHED</code> event.
20+
*
21+
* @author Tomer Shalev
22+
*
23+
*/
24+
public class MovieClipButton extends FlexButton
25+
{
26+
/**
27+
* Event for Dropping the this button
28+
*/
29+
public static const ANIMATION_FINISHED: String = "ANIMATION_FINISHED";
30+
[Event(name="ANIMATION_FINISHED", type="starling.events.Event")]
31+
32+
private var _mc_skin: MovieClip = null;
33+
private var _up_skin: FlexImage = null;
34+
private var _sound: Sound = null;
35+
36+
public function MovieClipButton(mc: MovieClip, sound:Sound = null)
37+
{
38+
super();
39+
40+
_mc_skin = mc;
41+
_sound = sound;
42+
}
43+
44+
override protected function feathersControl_addedToStageHandler(event:Event):void
45+
{
46+
super.feathersControl_addedToStageHandler(event);
47+
48+
addEventListener(TouchEvent.TOUCH, touchHandler);
49+
}
50+
51+
override protected function feathersControl_removedFromStageHandler(event:Event):void
52+
{
53+
super.feathersControl_removedFromStageHandler(event);
54+
55+
Starling.juggler.remove(_mc_skin);
56+
57+
removeEventListener(TouchEvent.TOUCH, touchHandler);
58+
_mc_skin.removeEventListener(Event.COMPLETE, mc_onComplete);
59+
}
60+
61+
override protected function initialize():void
62+
{
63+
super.initialize();
64+
65+
if(_sound != null)
66+
_mc_skin.setFrameSound(0, _sound);
67+
68+
super.downSkin = _mc_skin;
69+
70+
_up_skin = new FlexImage();
71+
_up_skin.scaleMode = FlexImage.SCALEMODE_STRECTH;
72+
_up_skin.source = _mc_skin.getFrameTexture(0);
73+
74+
super.defaultSkin = _up_skin;
75+
76+
_mc_skin.addEventListener(Event.COMPLETE, mc_onComplete);
77+
78+
_mc_skin.stop();
79+
80+
Starling.juggler.add(_mc_skin);
81+
}
82+
83+
private function btnPlay_onTriggered(event:Event):void
84+
{
85+
_mc_skin.play();
86+
}
87+
88+
private function btnStop_onTriggered(event:Event):void
89+
{
90+
_mc_skin.stop();
91+
}
92+
93+
override protected function draw():void
94+
{
95+
super.draw();
96+
}
97+
98+
override public function dispose():void
99+
{
100+
super.dispose();
101+
}
102+
103+
override public function set defaultSkin(value:DisplayObject):void
104+
{
105+
throw new Error("Not Supported for " + getQualifiedClassName(this));
106+
}
107+
override public function set downSkin(value:DisplayObject):void
108+
{
109+
throw new Error("Not Supported for " + getQualifiedClassName(this));
110+
}
111+
override public function set upSkin(value:DisplayObject):void
112+
{
113+
throw new Error("Not Supported for " + getQualifiedClassName(this));
114+
}
115+
116+
private function touchHandler(event: TouchEvent = null):void
117+
{
118+
if(event == null)
119+
return;
120+
121+
var touch: Touch = event.getTouch(stage);
122+
123+
if(touch==null)
124+
return;
125+
126+
if(touch.phase == TouchPhase.BEGAN) {
127+
_mc_skin.currentFrame = 0;
128+
_mc_skin.loop = false;
129+
_mc_skin.play();
130+
trace("begin playing");
131+
}
132+
else if(touch.phase == TouchPhase.ENDED) {
133+
_mc_skin.stop();
134+
trace("stopped playing");
135+
}
136+
137+
}
138+
139+
private function mc_onComplete(event: Event):void
140+
{
141+
trace("MovieClipButton.mc_onComplete");
142+
_mc_skin.stop();
143+
144+
dispatchEventWith(ANIMATION_FINISHED);
145+
}
146+
147+
}
148+
149+
}

0 commit comments

Comments
 (0)