My favorites | Sign in
Project Logo
                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
/*

The contents of this file are subject to the Mozilla Public License Version
1.1 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.mozilla.org/MPL/

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
for the specific language governing rights and limitations under the License.

The Original Code is ASGard Framework.

The Initial Developer of the Original Code is
ALCARAZ Marc (aka eKameleon) <ekameleon@gmail.com>.
Portions created by the Initial Developer are Copyright (C) 2004-2009
the Initial Developer. All Rights Reserved.

Contributor(s) :

*/

package asgard.display
{
import asgard.events.FrameLabelEvent;

import system.data.maps.HashMap;
import system.events.CoreEventDispatcher;
import system.events.Delegate;

import flash.display.FrameLabel;
import flash.display.MovieClip;
import flash.events.Event;

/**
* Dispatched when the inspector is in progress.
* @eventType asgard.events.FrameLabelEvent.FRAME_LABEL
*/
[Event(name="frameLabel", type="asgard.events.FrameLabelEvent")]

/**
* The TimelineInspector class use composition to dispatch action events during the MovieClip playing.
* <p><b>Example :</b></p>
* <pre class="prettyprint">
* package examples
* {
* import asgard.display.TimelineInspector;
* import asgard.events.FrameLabelEvent;
*
* import flash.display.FrameLabel;
* import flash.display.MovieClip;
* import flash.display.Sprite;
* import flash.display.StageAlign;
* import flash.display.StageScaleMode;
* import flash.events.MouseEvent;
* import flash.utils.setTimeout;
*
* public dynamic class TestTimelineInspector extends Sprite
* {
* public function TestTimelineInspector()
* {
* // stage
*
* stage.align = StageAlign.TOP_LEFT ;
* stage.scaleMode = StageScaleMode.NO_SCALE ;
*
* // target
*
* mc = getChildByName("mc") as MovieClip ; // MovieClip in the stage of the application
* mc.useHandCursor = true ;
* mc.buttonMode = true ;
*
* mc.addEventListener( MouseEvent.CLICK , click ) ;
*
* trace("Click the movieclip to start the example.") ;
*
* // timeline inspector
*
* var inspector:TimelineInspector = new TimelineInspector( mc , true ) ;
* inspector.addEventListener( FrameLabelEvent.FRAME_LABEL , frameLabel ) ;
*
* }
*
* public var mc:MovieClip ;
*
* public function click( e:MouseEvent ):void
* {
* mc.play() ;
* }
*
* public function frameLabel( e:FrameLabelEvent ):void
* {
* var frame:FrameLabel = e.frameLabel ;
* trace( "progress :: " + frame.frame + " : " + frame.name ) ;
* switch( frame.name )
* {
* case "finish" :
* {
* mc.stop() ;
* break ;
* }
* case "middle" :
* {
* mc.stop() ;
* setTimeout(mc.play, 5000) ; // pause 5 seconds
* break ;
* }
* }
* }
* }
* }
* </pre>
*/
public class TimelineInspector extends CoreEventDispatcher
{
/**
* Creates a new TimelineInspector instance.
* @param target The MovieClip reference of this iterator.
* @param autoStop This boolean flag indicates if the specified MovieClip target reference is stopped when the inspector target the MovieClip reference.
* @throws ArgumentError If the passed-in MovieClip reference is null or undefined.
*/
public function TimelineInspector( target:MovieClip , autoStop:Boolean = false , mode:String = "injector" )
{
if ( target == null )
{
throw new ArgumentError( this + " can't be instanciate with an empty MovieClip reference in argument of the constructor.") ;
}
this._map = new HashMap() ;
this._target = target ;
this.mode = mode ;
initialize() ;
if ( autoStop )
{
this._target.stop() ;
}
}

/**
* The "injector" mode of the inspector.
*/
public static const INJECTOR:String = "injector" ;

/**
* The "timeline" mode of the inspector.
*/
public static const TIMELINE:String = "timeline" ;

/**
* Determinates the mode of the inspector.
* <p>When the "injector" mode is defines, the events are dispatched with a set of methods injected in the timeline scripts. </p>
* <p>When the "timeline" mode is defines, the user can use script in the frames of the MovieClip but the inspector use the Event.ENTER_FRAME event to dispatch the events (CPU usage).</p>
*/
public function get mode():String
{
return _mode ;
}

/**
* @private
*/
public function set mode( value:String ):void
{
var b:Boolean = _flag ;
if ( b )
{
dispose() ;
}
_mode = value || INJECTOR ;
if ( b )
{
initialize() ;
}
}

/**
* Indicates the target reference of this iterator.
*/
public function get target():MovieClip
{
return _target ;
}

/**
* Initialize the inspector.
*/
public function initialize():void
{
var frame:int ;
var currentLabels:Array = _target.currentLabels ;
var element:FrameLabel ;
if ( _mode == TIMELINE )
{
_target.addEventListener( Event.ENTER_FRAME, _enterFrame ) ;
for each( element in currentLabels )
{
_map.put( element.frame , element ) ;
}
}
else
{
for each( element in currentLabels )
{
frame = element.frame - 1 ;
frame = frame > 1 ? frame : 1 ;
_target.addFrameScript( frame , Delegate.create(this, _dispatch, element ) ) ;
}
}
_flag = true ;
}

/**
* Unregisters all notifications in the inspector.
*/
public function dispose():void
{
if ( _flag )
{
if ( _mode == TIMELINE )
{
_prev = -1 ;
_map.clear() ;
_target.removeEventListener(Event.ENTER_FRAME, _enterFrame) ;
}
else
{
var frame:int ;
var currentLabels:Array = _target.currentLabels ;
for each( var element:FrameLabel in currentLabels )
{
frame = element.frame - 1 ;
frame = frame > 1 ? frame : 1 ;
_target.addFrameScript( frame , null ) ;
}
}
_flag = false ;
}
}

/**
* @private
*/
private var _flag:Boolean ;

/**
* @private
*/
private var _map:HashMap ;

/**
* @private
*/
private var _mode:String ;

/**
* @private
*/
private var _prev:int = -1 ;

/**
* @private
*/
private var _target:MovieClip ;

/**
* @private
*/
private function _dispatch( frame:FrameLabel ):void
{
dispatchEvent( new FrameLabelEvent( FrameLabelEvent.FRAME_LABEL , frame ) ) ;
}

/**
* @private
*/
private function _enterFrame( e:Event ):void
{
e.stopImmediatePropagation() ;
var frame:int = _target.currentFrame;
if ( _prev != frame && _map.containsKey( frame ) )
{
_prev = frame ;
dispatchEvent( new FrameLabelEvent( FrameLabelEvent.FRAME_LABEL , _map.get( frame ) as FrameLabel ) ) ;
}
}
}
}
Show details Hide details

Change log

r150 by ekameleon on Oct 08, 2009   Diff
Create the KeyInspector class + example in
asgard.ui
Go to: 
Project members, sign in to write a code review

Older revisions

r114 by ekameleon on Jul 13, 2009   Diff
Refactoring Background class + fix
examples in asgard.net
r103 by ekameleon on Jul 02, 2009   Diff
Fix Background class, begin to
implement the fusion between
Background and the lunas
AbstractComponent class + refactoring
r96 by ekameleon on Jun 05, 2009   Diff
Refactoring
All revisions of this file

File info

Size: 9666 bytes, 287 lines
Hosted by Google Code