My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
/*

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.logging.logger;

import vegas.errors.NullPointerError;

import flash.display.FrameLabel;
import flash.display.MovieClip;

/**
* The TimeLineScript class use composition to register script function over MovieClip timelines.
* <p><b>Example :</b></p>
* <pre class="prettyprint">
* import asgard.display.TimelineScript ;
*
* var ts:TimelineScript = new TimelineScript( mc , true ) ; // mc a MovieClip in the stage
*
* var start:Function = function()
* {
* trace("start") ;
* }
*
* var pause:Function = function()
* {
* trace("pause") ;
* mc.stop() ;
* setTimeout( mc.play , 4000 ) ; // pause 4 s
* }
*
* var finish:Function = function()
* {
* trace("finish") ;
* mc.stop() ;
* }
*
* ts.put( "begin" , start ) ;
* ts.put( "middle" , pause ) ;
* ts.put( "finish" , finish ) ;
*
* var click:Function = function( e:MouseEvent ):void
* {
* mc.play() ;
* trace("click") ;
* e.target.removeEventListener( MouseEvent.CLICK , click ) ;
* mc.buttonMode = false ;
* }
*
* mc.useHandCursor = true ;
* mc.buttonMode = true ;
* mc.addEventListener( MouseEvent.CLICK , click ) ;
* </pre>
*/
public class TimelineScript
{
/**
* Creates a new TimelineScript instance.
* @param target The MovieClip reference of this iterator.
* @param autoStop This boolean flag indicates if the specified MovieClip target reference is stopped.
*/
public function TimelineScript( target:MovieClip , autoStop:Boolean=false )
{
super();
if (target == null)
{
throw new ArgumentError( this + " can't be instanciate with an empty MovieClip reference in argument of the constructor.") ;
}
this._target = target ;
if (autoStop)
{
this._target.stop() ;
}
}

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

/**
* Registers a script function in the frame specified by the label or index value passed-in the first argument of the method.
* @param index A String label name or a uint frame index value.
* @param script The Function instruction to register.
* @return true if the register is success.
*/
public function put( index:* , script:Function ):Boolean
{
try
{
var num:uint ;
if ( index is uint )
{
num = index as uint ;
}
else if ( index is String )
{
num = resolve( index as String ) ;
}
_target.addFrameScript( num , script ) ;
return true ;
}
catch(e:Error)
{
logger.error( this + " put failed : " + e.toString() ) ;
return false ;
}
return false ;
}

/**
* Unregisters a script function in the frame specified by the label or index value passed-in argument of the method.
* @param index A String label name or a uint frame index value.
*/
public function remove( index:* ):void
{
var num:int ;
if ( index is int )
{
num = index as int ;
}
else if ( index is String )
{
num = resolve( index as String ) ;
}
_target.addFrameScript( num , null ) ;
}

/**
* Indicates if the specified passed-in label value is in the MovieClip target.
*/
protected function resolve( label:String=null ):int
{
if ( label == null || label.length == 0 )
{
throw new ArgumentError( this + " resolve label failed with a 'null' or 'undefined' label argument.") ;
}
var frame:uint ;
var currentLabels:Array = _target.currentLabels ;
for each( var element:FrameLabel in currentLabels )
{
if (element.name == label )
{
frame = element.frame - 1 ;
return frame > 1 ? frame : 1 ;
}
} ;
throw new NullPointerError( this + " resolve the label '" + label + "' failed, the specified label don't exist in the internal MovieClip reference." ) ;
}
/**
* @private
*/
private var _target:MovieClip ;
}
}

Change log

r103 by ekameleon on Jul 2, 2009   Diff
Fix Background class, begin to implement
the fusion between Background and the
lunas AbstractComponent class +
refactoring
Go to: 
Project members, sign in to write a code review

Older revisions

r67 by ekameleon on Mar 29, 2009   Diff
Minor refactoring
r61 by ekameleon on Mar 17, 2009   Diff
TimelineInspector + FrameLabelEvent
class + examples
r55 by ekameleon on Mar 10, 2009   Diff
Background optimize :
minHeight/maxHeight =
minWidth/maxWidth + align are now r/w
+ refactoring examples + remove
hashCode in the IDisplayObject objects
...
All revisions of this file

File info

Size: 5979 bytes, 179 lines
Powered by Google Project Hosting