| Package | system.process |
| Class | public class Batch |
| Inheritance | Batch Object |
| Implements | Collection, Runnable, Stoppable |
Action objects.
All Action objects are processed as a single unit.
This class use an internal typed Collection to register all Runnable objects.
Example :
package examples
{
import system.process.Batch;
import flash.display.Sprite;
import flash.events.KeyboardEvent;
import flash.geom.Point;
[SWF(width="740", height="480", frameRate="24", backgroundColor="#666666")]
public class BatchExample extends Sprite
{
public function BatchExample()
{
var s1:Square = new Square( 50 , 50 , 0xFF0000 ) ;
var s2:Square = new Square( 50 , 100 , 0x00FF00 ) ;
var s3:Square = new Square( 50 , 150 , 0x0000FF ) ;
s1.finish = new Point( 600 , 50 ) ;
s2.finish = new Point( 600 , 100 ) ;
s3.finish = new Point( 600 , 150 ) ;
addChild(s1) ;
addChild(s2) ;
addChild(s3) ;
command = new Batch() ;
command.add( s1 ) ;
command.add( s2 ) ;
command.add( s3 ) ;
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown) ;
}
public var command:Batch ;
public function keyDown( e:KeyboardEvent ):void
{
command.run() ;
}
}
}
import system.process.Runnable;
import flash.display.Sprite;
import flash.events.Event;
import flash.filters.DropShadowFilter;
import flash.geom.Point;
class Square extends Sprite implements Runnable
{
public function Square( x:int = 0 , y:int = 0 , color:uint = 0xFFFFFF ):void
{
graphics.beginFill( color ) ;
graphics.drawRect(0, 0, 30, 30) ;
filters = [ new DropShadowFilter(1,60,0,0.7,4,4) ] ;
this.x = x ;
this.y = y ;
}
public var finish:Point ;
public function run(...arguments:Array):void
{
if ( finish != null )
{
addEventListener(Event.ENTER_FRAME , enterFrame ) ;
}
}
protected function enterFrame( e:Event ):void
{
var dx:Number = Math.round( ( finish.x - x ) * 0.3 ) ;
var dy:Number = Math.round( ( finish.y - y ) * 0.3 ) ;
x += dx ;
y += dy ;
if ( dx == 0 && dy == 0 )
{
removeEventListener(Event.ENTER_FRAME , enterFrame ) ;
}
}
}
| Method | Defined By | ||
|---|---|---|---|
Batch(init:Array = null)
Creates a new Batch instance. | Batch | ||
add(o:*):Boolean
Inserts an element in the collection. | Batch | ||
clear():void
Removes all elements in the collection. | Batch | ||
clone():*
Returns a shallow copy of the object. | Batch | ||
contains(o:*):Boolean
Returns true if this collection contains the specified element. | Batch | ||
get(key:*):*
Returns the element from this collection at the passed key index. | Batch | ||
indexOf(o:*, fromIndex:uint = 0):int
Returns the index of an element in the collection. | Batch | ||
isEmpty():Boolean
Returns true if this collection contains no elements. | Batch | ||
Returns the iterator reference of the object. | Batch | ||
remove(o:*):*
Removes a single instance of the specified element from this collection, if it is present (optional operation). | Batch | ||
run(... arguments):void
Runs the process. | Batch | ||
size():uint
Returns the number of elements in this collection. | Batch | ||
stop():void
Stops all commands in the batch. | Batch | ||
toArray():Array
Returns an array containing all of the elements in this collection. | Batch | ||
toSource(indent:int = 0):String
Returns the source code string representation of the object. | Batch | ||
toString():String
Returns the string representation of this instance. | Batch | ||
Returns the vector containing all of the Runnable objects in this batch. | Batch | ||
| Batch | () | Constructor |
public function Batch(init:Array = null)Creates a new Batch instance.
Parametersinit:Array (default = null) — The optional Array of Runnable objects to fill the batch.
|
| add | () | method |
public function add(o:*):BooleanInserts an element in the collection.
Parameters
o:* |
Boolean |
| clear | () | method |
public function clear():voidRemoves all elements in the collection.
| clone | () | method |
public function clone():*Returns a shallow copy of the object.
Returns* — a shallow copy of the object.
|
| contains | () | method |
public function contains(o:*):Boolean
Returns true if this collection contains the specified element.
Parameters
o:* |
Boolean — true if this collection contains the specified element.
|
| get | () | method |
public function get(key:*):*Returns the element from this collection at the passed key index.
Parameters
key:* |
* — the element from this collection at the passed key index.
|
| indexOf | () | method |
public function indexOf(o:*, fromIndex:uint = 0):intReturns the index of an element in the collection.
Parameters
o:* | |
fromIndex:uint (default = 0) |
int — the index of an element in the collection.
|
| isEmpty | () | method |
public function isEmpty():Boolean
Returns true if this collection contains no elements.
Boolean — true if this collection contains no elements.
|
| iterator | () | method |
public function iterator():IteratorReturns the iterator reference of the object.
ReturnsIterator — the iterator reference of the object.
|
| remove | () | method |
public function remove(o:*):*Removes a single instance of the specified element from this collection, if it is present (optional operation).
Parameters
o:* |
* |
| run | () | method |
public function run(... arguments):voidRuns the process.
Parameters
... arguments |
| size | () | method |
public function size():uintReturns the number of elements in this collection.
Returnsuint — the number of elements in this collection.
|
| stop | () | method |
public function stop():voidStops all commands in the batch.
| toArray | () | method |
public function toArray():ArrayReturns an array containing all of the elements in this collection.
Note: The returned Array is a reference of the internal Array used in the Collection to store the items. It's not a shallow copy of it.
ReturnsArray — an array containing all of the elements in this collection.
|
| toSource | () | method |
public function toSource(indent:int = 0):StringReturns the source code string representation of the object.
Parameters
indent:int (default = 0) |
String — the source code string representation of the object.
|
| toString | () | method |
public function toString():StringReturns the string representation of this instance.
ReturnsString — the string representation of this instance.
|
| toVector | () | method |
public function toVector():Vector.<Runnable>Returns the vector containing all of the Runnable objects in this batch.
ReturnsVector.<Runnable> — the vector containing all of the Runnable objects in this batch.
|