Вы находитесь на странице: 1из 106

ADOBE FLASH PLATFORM

. - http://help.adobe.com/ru_RU/legalnotices/index.html.

12.10.2011.

iii

1.


...................................................... 1

..................................................................... 3

......................................................................................... 3

2.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

................................................................................................... 5

................................................................................. 7

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

20

MIP-

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

3D-

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

3.
Flash Player 10.1

. . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34

ENTER_FRAME

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

4. ActionScript 3.0
Vector Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
API-

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44

5.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

12.10.2011.

FLASH PLATFORM

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

6.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

Flash Remoting

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91

7.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
StageVideo

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

8. SQL


SQL

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

SQL

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100

9.
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102

12.10.2011.

iv

1.
Adobe AIR Adobe Flash Player ,
, , .
,
. :



ActionScript 3.0



SQL

,
AIR Flash Player. , .
, Flash Player 10.1 AIR 2.5.
AIR Flash Player.

, ,
, Flash Platform . ,
. ,
. ,
. , 30
.
.
Adobe Flash Builder Flash Professional.
. , ActionScript, ,
[SWF(frameRate="24")] . MXML Application
WindowedApplication frameRate.
, : , enterFrame
.

12.10.2011.

FLASH PLATFORM

( enterFrame),
. .
,
. .
.
, , .
.
,
.
enterFrame. ,
.
.
. (
).
. , updateAfterEvent,
, .
updateAfterEvent, - .
, , .
,
. .
,
, . ,
, ,
. ,
, .
( ) ,
. ,
. ,
, 30 .
.
. , .
Flash Platform
. .

Flash Player ( (Ted


Patrick))

ActionScript ( (Trevor McCauley))


, Adobe AIR:
http://www.adobe.com/go/learn_fp_air_perf_tv_ru ( MAX,
(Sean Christmann))

12.10.2011.

FLASH PLATFORM


.

.
. . ,
?
?
, .

?
?
?
?
?
?
?

?

?
.

. ,
, -
.
,
. ( .
50.)

.


.
,
.
, .
.
, , ,
. Flash Platform
,
, . ,

, .

12.10.2011.

FLASH PLATFORM

: .
.
.
,
.
. ,
, , ,
. . ,
,
. , ,
. ,
.
.
, .
101.
, , .
.

AIR: http://www.adobe.com/go/learn_fp_goldman_tv_ru
( MAX, (Oliver Goldman))

Adobe AIR:
http://www.adobe.com/go/learn_fp_air_perf_devnet_ru ( Adobe Developer Connection
(Oliver Goldman), )

12.10.2011.

2.
,
.
, , .


.
ActionScript 3.0 .

. Shape. ,
, Sprite.
MovieClip. .
.
trace(getSize(new Shape()));
// output: 236
trace(getSize(new Sprite()));
// output: 412
trace(getSize(new MovieClip()));
// output: 440

getSize() , , . ,
MovieClip Shape ;
MovieClip .


getSize()
.
, String, 4 8 .
.

12.10.2011.

FLASH PLATFORM

// Primitive types
var a:Number;
trace(getSize(a));
// output: 8
var b:int;
trace(getSize(b));
// output: 4
var c:uint;
trace(getSize(c));
// output: 4
var d:Boolean;
trace(getSize(d));
// output: 4
var e:String;
trace(getSize(e));
// output: 4

Number, 64- , ActionScript Virtual


Machine (AVM) 8 , .
4 .
// Primitive types
var a:Number = 8;
trace(getSize(a));
// output: 4
a = Number.MAX_VALUE;
trace(getSize(a));
// output: 8

String.
String:
var name:String;
trace(getSize(name));
// output: 4
name = "";
trace(getSize(name));
// output: 24
name = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum
has been the industry's standard dummy text ever since the 1500s, when an unknown printer took
a galley of type and scrambled it to make a type specimen book. It has survived not only five
centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It
was popularized in the 1960s with the release of Letraset sheets containing Lorem Ipsum
passages, and more recently with desktop publishing software like Aldus PageMaker including
versions of Lorem Ipsum.";
trace(getSize(name));
// output: 1172

getSize()
.

12.10.2011.

FLASH PLATFORM


.

. , :
const MAX_NUM:int = 18;
const COLOR:uint = 0xCCCCCC;
var area:Rectangle;
for (var:int = 0; i < MAX_NUM; i++)
{
// Do not use the following code
area = new Rectangle(i,0,1,10);
myBitmapData.fillRect(area,COLOR);
}

Rectangle
, . :
const MAX_NUM:int = 18;
const COLOR:uint = 0xCCCCCC;
// Create the rectangle outside the loop
var area:Rectangle = new Rectangle(0,0,1,10);
for (var:int = 0; i < MAX_NUM; i++)
{
area.x = i;
myBitmapData.fillRect(area,COLOR);
}

.

BitmapData. .

12.10.2011.

FLASH PLATFORM

var myImage:BitmapData;
var myContainer:Bitmap;
const MAX_NUM:int = 300;
for (var i:int = 0; i< MAX_NUM; i++)
{
// Create a 20 x 20 pixel bitmap, non-transparent
myImage = new BitmapData(20,20,false,0xF0D062);
// Create a container for each BitmapData instance
myContainer = new Bitmap(myImage);
// Add it to the display list
addChild(myContainer);
// Place each container
myContainer.x = (myContainer.width + 8) * Math.round(i % 20);
myContainer.y = (myContainer.height + 8) * int(i / 20);
}

. int
, Math.floor().
.

BitmapData,
Bitmap. .

12.10.2011.

FLASH PLATFORM

// Create a single 20 x 20 pixel bitmap, non-transparent


var myImage:BitmapData = new BitmapData(20,20,false,0xF0D062);
var myContainer:Bitmap;
const MAX_NUM:int = 300;
for (var i:int = 0; i< MAX_NUM; i++)
{
// Create a container referencing the BitmapData instance
myContainer = new Bitmap(myImage);
// Add it to the display list
addChild(myContainer);
// Place each container
myContainer.x = (myContainer.width + 8) * Math.round(i % 20);
myContainer.y = (myContainer.height + 8) * int(i / 20);
}

700 ,
.
BitmapData Bitmap.
// Create a single 20 x 20 pixel bitmap, non-transparent
var myImage:BitmapData = new BitmapData(20,20,false,0xF0D062);
var myContainer:Bitmap;
const MAX_NUM:int = 300;
for (var i:int = 0; i< MAX_NUM; i++)
{
// Create a container referencing the BitmapData instance
myContainer = new Bitmap(myImage);
// Add it to the DisplayList
addChild(myContainer);
// Place each container
myContainer.x = (myContainer.width + 8) * Math.round(i % 20);
myContainer.y = (myContainer.height + 8) * int(i / 20);
// Set a specific rotation, alpha, and depth
myContainer.rotation = Math.random()*360;
myContainer.alpha = Math.random();
myContainer.scaleX = myContainer.scaleY = Math.random();
}

12.10.2011.

FLASH PLATFORM


57


.

. ,
, Array Vector.
, .
null,
. , .
, .
, .
.

12.10.2011.

10

FLASH PLATFORM

package
{
import flash.display.Sprite;
public final class
{
private static
private static
private static
private static
private static

SpritePool
var
var
var
var
var

MAX_VALUE:uint;
GROWTH_VALUE:uint;
counter:uint;
pool:Vector.<Sprite>;
currentSprite:Sprite;

public static function initialize( maxPoolSize:uint, growthValue:uint ):void


{
MAX_VALUE = maxPoolSize;
GROWTH_VALUE = growthValue;
counter = maxPoolSize;
var i:uint = maxPoolSize;
pool = new Vector.<Sprite>(MAX_VALUE);
while( --i > -1 )
pool[i] = new Sprite();
}
public static function getSprite():Sprite
{
if ( counter > 0 )
return currentSprite = pool[--counter];
var i:uint = GROWTH_VALUE;
while( --i > -1 )
pool.unshift ( new Sprite() );
counter = GROWTH_VALUE;
return getSprite();
}
public static function disposeSprite(disposedSprite:Sprite):void
{
pool[counter++] = disposedSprite;
}
}
}

SpritePool . getSprite()
, disposeSprite() .
. , .
.
. .
12. SpritePool .

12.10.2011.

11

FLASH PLATFORM

const MAX_SPRITES:uint = 100;


const GROWTH_VALUE:uint = MAX_SPRITES >> 1;
const MAX_NUM:uint = 10;
SpritePool.initialize ( MAX_SPRITES,

GROWTH_VALUE );

var currentSprite:Sprite;
var container:Sprite = SpritePool.getSprite();
addChild ( container );
for ( var i:int = 0; i< MAX_NUM; i++ )
{
for ( var j:int = 0; j< MAX_NUM; j++ )
{
currentSprite = SpritePool.getSprite();
currentSprite.graphics.beginFill ( 0x990000 );
currentSprite.graphics.drawCircle ( 10, 10, 10 );
currentSprite.x = j * (currentSprite.width + 5);
currentSprite.y = i * (currentSprite.width + 5);
container.addChild ( currentSprite );
}
}

,
.
stage.addEventListener ( MouseEvent.CLICK, removeDots );
function removeDots ( e:MouseEvent ):void
{
while (container.numChildren > 0 )
SpritePool.disposeSprite (container.removeChildAt(0) as Sprite );
}

. Sprite.
, dispose() SpritePool, .


.
Flash Player.
, . , delete,
ActionScript 1.0 2.0, ActionScript 3.0.
.
. Adobe AIR Flash Player.
, Sprite null:

12.10.2011.

12

FLASH PLATFORM

var mySprite:Sprite = new Sprite();


// Set the reference to null, so that the garbage collector removes
// it from memory
mySprite = null;

, null .
, .
.
, .
, .
, .
.
,
.
.
, null,
. .
.
. null .
, . ,
null.
System.gc(), Adobe AIR
Flash Player. , Adobe Flash Builder,
.
.
. ,
.
removeEventListener(), null.
, , , .
, BitmapData dispose().
BitmapData 1,8 . 1,8 ,
System.totalMemory .
trace(System.totalMemory / 1024);
// output: 43100
// Create a BitmapData instance
var image:BitmapData = new BitmapData(800, 600);
trace(System.totalMemory / 1024);
// output: 44964

BitmapData ()
.

12.10.2011.

13

FLASH PLATFORM

trace(System.totalMemory / 1024);
// output: 43100
// Create a BitmapData instance
var image:BitmapData = new BitmapData(800, 600);
trace(System.totalMemory / 1024);
// output: 44964
image.dispose();
image = null;
trace(System.totalMemory / 1024);
// output: 43084

dispose() , -
null, . BitmapData ,
dispose() null .
. Flash Player 10.1 AIR 1.5.2 disposeXML()
System. XML ,
XML.


29


.
, ,
.
,
, .


64


, Flash Player 16- ,
32- 16 .

. Flash Player 10.1 Windows Mobile.
. , Flash Player 10.1, , ,
32 (4 ). 300 x 300 350
(300*300*4/1024). 175 .
, 16
. ,
, PNG, GIF JPG.

12.10.2011.

14

FLASH PLATFORM

, 16 , 32 . , ,
. .
16-
, 32- .

BitmapData
BitmapData.
Flash Player 10.1 AIR 2.5 BitmapData,
. BitmapData
BitmapData .

. [Embed].
. , Flash
Player 10.1 AIR 2.5 .
.
, Flash Player 10.1 AIR 2.5,
, .

Flash Player 10.1 AIR 2.5

Flash Player 10.1 AIR 2.5


BitmapData .
.

12.10.2011.

15

FLASH PLATFORM

Flash Player 10.1 AIR 2.5

,
. Star:
const MAX_NUM:int = 18;
var star:BitmapData;
var bitmap:Bitmap;
for (var i:int = 0; i<MAX_NUM; i++)
{
for (var j:int = 0; j<MAX_NUM; j++)
{
star = new Star(0,0);
bitmap = new Bitmap(star);
bitmap.x = j * star.width;
bitmap.y = i * star.height;
addChild(bitmap)
}
}

12.10.2011.

16

FLASH PLATFORM

, Flash Player 10 1008 .


Flash Player 10.1
4 .
BitmapData.
const MAX_NUM:int = 18;
var star:BitmapData;
var bitmap:Bitmap;
for (var i:int = 0; i<MAX_NUM; i++)
{
for (var j:int = 0; j<MAX_NUM; j++)
{
star = new Star(0,0);
bitmap = new Bitmap(star);
bitmap.x = j * star.width;
bitmap.y = i * star.height;
addChild(bitmap)
}
}
var ref:Bitmap = getChildAt(0) as Bitmap;
ref.bitmapData.pixelDissolve(ref.bitmapData, ref.bitmapData.rect, new
Point(0,0),Math.random()*200,Math.random()*200, 0x990000);

Star.

12.10.2011.

17

FLASH PLATFORM


. BitmapData,
, , .
.

setPixel()

12.10.2011.

18

FLASH PLATFORM

.
8 Flash Player 10.1 AIR 2.5.
.
, beginBitmapFill().
var container:Sprite = new Sprite();
var source:BitmapData = new Star(0,0);
// Fill the surface with the source BitmapData
container.graphics.beginBitmapFill(source);
container.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
addChild(container);

BitmapData.
( Star )
Matrix, . Matrix beginBitmapFill().
var container:Sprite = new Sprite();
container.addEventListener(Event.ENTER_FRAME, rotate);
var source:BitmapData = new Star(0,0);
var matrix:Matrix = new Matrix();
addChild(container);
var angle:Number = .01;
function rotate(e:Event):void
{
// Rotate the stars
matrix.rotate(angle);
// Clear the content
container.graphics.clear();
// Fill the surface with the source BitmapData
container.graphics.beginBitmapFill(source,matrix,true,true);
container.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
}

ActionScript.
.
.

12.10.2011.

19

FLASH PLATFORM

BitmapData
.
. ,
.
.
. ,
Shape .

, , Pixel Bender.
, , ,
Pixel Bender.
.
. ,

.

12.10.2011.

20

21

FLASH PLATFORM


. ,
, .
Flash Player 10.1 AIR 2.5 .
30 , ,
, .
, .
, , .
. 30
. , 30
.
. .
, ;
-
.
, , Adobe
Photoshop, , .
, ActionScript. ,
,
, .
.
, , .

MIP-
MIP- .

12.10.2011.

FLASH PLATFORM

, Flash Player 10.1 AIR 2.5 ,


MIP-. Flash Player 9 AIR 1.0 MIP,
.
. MIP-
. MIP-
. MIP- ,
.
, MIP- . ,
250 x 250 MIP- 125 x 125, MIP . .
, ,
, : 256 x 256, 512 x 512, 1024 x 1024 .
, 1024 x 1024
. MIP-

.
. 1024
x 1024, 64 x 64,
. ,
512 x 512, 256 x 256, 128 x 128 64 x 64.
Flash Player 10.1 AIR 2.5 MIP-
.
4 (1024 x 1024) MIP- 16 (64 x 64).
MIP- .
64 x 64, 4
. MIP- ,
. , MIP-
, MIP-
. , 1:8,
1:4, 1:2 1:1 ,
. , 1:1
.
JPEG MIP- .
MIP-
MIP- . MIP ,
, . JPEG
, MIP-.
. MIP-.
, , .
.
, .

12.10.2011.

22

FLASH PLATFORM

3D-
3D- .
Flash Player 10 AIR 1.5 3D,
. rotationX
rotationY drawTriangles() Graphics.
z. , , ,
, .
,
.

.
3D- AIR Flash Player
, AIR 2.0.1 AIR 2.5 . Flash Player
.
3D- API-
. 3D-,
Flash Player 10 AIR 1.5, , drawTriangles(),
.
, 3D-
API- .
ActionScript,
.

12.10.2011.

23

FLASH PLATFORM

AIR 2.0.1 AIR 2.5 , renderMode


GPU, 3D- .
renderMode CPU, 3D-
. Flash Player 10.1 3D-
.
3D- , ,
, .
, . , 3D . , 3D-
, 3D.


Adobe Flash Text Engine , .
TextField .
Flash Player 10 AIR 1.5 Adobe
Flash Text Engine (FTE), . FTE API , ActionScript 3.0,
flash.text.engine.
, , Flash Text Engine,
.
TextField, ActionScript,
, .


70


.
ActionScript 3.0 .
. dispatchEvent()
.
:
.
, ,
. , ,
.
dispatchEvent( new Event ( Event.COMPLETE ) );

Document .
addEventListener( Event.COMPLETE, onAnimationComplete );

12.10.2011.

24

FLASH PLATFORM

,
, .
, . ,
Event.ENTER_FRAME .

. .

12.10.2011.

25

26

3.
.
, ,
.

Flash Player
10.1
Flash Player 10.1 ,
. SWF, , Flash Player .


. Adobe AIR.
Flash Player 10.1
( ), .
, ,
SWF- .
Flash Player ,
.
, .
SWF- :

SWF- .
,
. ,
ActionScript , HTML- hasPriority true.
, SWF- ,
HTML- hasPriority.

SWF- .
HTML hasPriority SWF 2 .
, SWF- .


. Adobe AIR.
HTML hasPriority, SWF-.
Flash Player 10.1 HTML hasPriority.
<param name="hasPriority" value="true" />

12.10.2011.

FLASH PLATFORM

Flash Player, .
. SWF-,
.
: -,
SWF-. , ,
, . ,
, .
, hasPriority false.
SWF-, , hasPriority true.
hasPriority SWF-,
, .
. , Flash Player
, hasPriority true.
JavaScript ,
hasPriority. 1x1 0x0 ,
SWF- , - hasPriority. SWF- . (click
to play).
, hasPriority .

SWF
hasPriority
false

SWF
hasPriority
false

SWF
hasPriority
false

SWF
SWF
hasPriority

12.10.2011.

27

FLASH PLATFORM


SWF
hasPriority
false

SWF
hasPriority
false

SWF
hasPriority
true
SWF
SWF
hasPriority


Flash Player 10.1 AIR 2.5 ,
, , .
, . ,
,
, . 4
. AIR ,
.
ActionScript , Stage.frameRate
4 . ,
, 4 . , 4 ,
, (NetStream, Socket
NetConnection). , , .
, 250 (4 ) ,
.
,
.
. , Stage.frameRate
SWF-, 4 /.

12.10.2011.

28

FLASH PLATFORM

, .
. ,
. ,
. ,
.

, , A/V.
, 4 .

, A/V.
, .

.
SWF- .

Flash Player A/V.


Flash Player ,
A/V .

A/V.
, 4 .

.
.
,
. ,
, .
. , ActionScript
.


REMOVED_FROM_STAGE
ADDED_TO_STAGE.
.
.
, - ,
. , - Event.ENTER_FRAME.
, .
Event.REMOVED_FROM_STAGE Event.ADDED_TO_STAGE. ,
, .

12.10.2011.

29

FLASH PLATFORM

// Listen to keyboard events


stage.addEventListener(KeyboardEvent.KEY_DOWN, keyIsDown);
stage.addEventListener(KeyboardEvent.KEY_UP, keyIsUp);
// Create object to store key states
var keys:Dictionary = new Dictionary(true);
function keyIsDown(e:KeyboardEvent):void
{
// Remember that the key was pressed
keys[e.keyCode] = true;
if (e.keyCode==Keyboard.LEFT || e.keyCode==Keyboard.RIGHT)
{
runningBoy.play();
}
}
function keyIsUp(e:KeyboardEvent):void
{
// Remember that the key was released
keys[e.keyCode] = false;
for each (var value:Boolean in keys)
if ( value ) return;
runningBoy.stop();
}
runningBoy.addEventListener(Event.ENTER_FRAME, handleMovement);
runningBoy.stop();
var currentState:Number = runningBoy.scaleX;
var speed:Number = 15;
function handleMovement(e:Event):void
{
if (keys[Keyboard.RIGHT])
{
e.currentTarget.x += speed;
e.currentTarget.scaleX = currentState;
} else if (keys[Keyboard.LEFT])
{
e.currentTarget.x -= speed;
e.currentTarget.scaleX = -currentState;
}
}

12.10.2011.

30

FLASH PLATFORM

.
// Show or remove running boy
showBtn.addEventListener (MouseEvent.CLICK,showIt);
removeBtn.addEventListener (MouseEvent.CLICK,removeIt);
function showIt (e:MouseEvent):void
{
addChild (runningBoy);
}
function removeIt(e:MouseEvent):void
{
if (contains(runningBoy)) removeChild(runningBoy);
}

-
Event.ENTER_FRAME. , .
, ,
, .

12.10.2011.

31

FLASH PLATFORM

// Listen to Event.ADDED_TO_STAGE and Event.REMOVED_FROM_STAGE


runningBoy.addEventListener(Event.ADDED_TO_STAGE,activate);
runningBoy.addEventListener(Event.REMOVED_FROM_STAGE,deactivate);
function activate(e:Event):void
{
// Restart everything
e.currentTarget.addEventListener(Event.ENTER_FRAME,handleMovement);
}
function deactivate(e:Event):void
{
// Freeze the running boy - consumes fewer CPU resources when not shown
e.currentTarget.removeEventListener(Event.ENTER_FRAME,handleMovement);
e.currentTarget.stop();
}

,
Event.ENTER_FRAME, .
. ,
null .
, ,
. , ,
.
Flash Player 10 AIR 1.5 .
, ,
.

Loader. Loader Flash Player 9 AIR 1.0
Event.UNLOAD,
LoaderInfo. , .
Flash Player 10 AIR 1.5 Loader unloadAndStop().
SWF-, SWF .
SWF- , unload(),
.
var loader:Loader = new Loader();
loader.load ( new URLRequest ( "content.swf" ) );
addChild ( loader );
stage.addEventListener ( MouseEvent.CLICK, unloadSWF );
function unloadSWF ( e:MouseEvent ):void
{
// Unload the SWF file with no automatic object deactivation
// All deactivation must be processed manually
loader.unload();
}

12.10.2011.

32

FLASH PLATFORM

unloadAndStop(),
.
var loader:Loader = new Loader();
loader.load ( new URLRequest ( "content.swf" ) );
addChild ( loader );
stage.addEventListener ( MouseEvent.CLICK, unloadSWF );
function unloadSWF ( e:MouseEvent ):void
{
// Unload the SWF file with automatic object deactivation
// All deactivation is handled automatically
loader.unloadAndStop();
}

unloadAndStop() .

.
, SWF-, .
.
(, ) .
.
Event.ENTER_FRAME, Event.FRAME_CONSTRUCTED, Event.EXIT_FRAME, Event.ACTIVATE
Event.DEACTIVATE .



Event.ACTIVATE Event.DEACTIVATE.
(Event.ACTIVATE Event.DEACTIVATE) ,
. ,
. ,
.
, . , ,
.

12.10.2011.

33

FLASH PLATFORM

var originalFrameRate:uint = stage.frameRate;


var standbyFrameRate:uint = 0;
stage.addEventListener ( Event.ACTIVATE, onActivate );
stage.addEventListener ( Event.DEACTIVATE, onDeactivate );
function onActivate ( e:Event ):void
{
// restore original frame rate
stage.frameRate = originalFrameRate;
}
function onDeactivate ( e:Event ):void
{
// set frame rate to 0
stage.frameRate = standbyFrameRate;
}

, .
,
.

, .


55
29


.
, ,
.
, ,
. ,
, . mouseEnabled
mouseChildren.

12.10.2011.

34

FLASH PLATFORM

// Disable any mouse interaction with this InteractiveObject


myInteractiveObject.mouseEnabled = false;
const MAX_NUM:int = 10;
// Create a container for the InteractiveObjects
var container:Sprite = new Sprite();
for ( var i:int = 0; i< MAX_NUM; i++ )
{
// Add InteractiveObject to the container
container.addChild( new Sprite() );
}
// Disable any mouse interaction on all the children
container.mouseChildren = false;

, ,
, .

ENTER_FRAME
ENTER_FRAME .
, ,
Event.ENTER_FRAME.
ActionScript 3.0 .
Event.ENTER_FRAME, (DisplayObject).
. ActionScript ( ENTER_FRAME).
ENTER_FRAME ,
. Stage.frameRate.
, ENTER_FRAME. , , ,
, .
ENTER_FRAME,
. .
. ,
.
. , .
, .
10 /.
. updateAfterEvent() TimerEvent .
.
.

12.10.2011.

35

FLASH PLATFORM

// Use a low frame rate for the application


stage.frameRate = 10;
// Choose one update per second
var updateInterval:int = 1000;
var myTimer:Timer = new Timer(updateInterval,0);
myTimer.start();
myTimer.addEventListener( TimerEvent.TIMER, updateControls );
function updateControls( e:TimerEvent ):void
{
// Update controls here
// Force the controls to be updated on screen
e.updateAfterEvent();
}

updateAfterEvent() .
. - 10 /.
, ENTER_FRAME
, ,
. SWF-,
.
Timer
enterFrame .

enterFrame
. enterFrame
, , .
enterFrame
. .
Timer.
Timer .
, :

Timer
.
, Timer ,
100 . Timer ,
, 2000 .

Timer,
delay.
, , 100 ,
200 . Timer, delay 100
. timer ,
200 .
:

12.10.2011.

36

FLASH PLATFORM

var timer:Timer = new Timer(100);


timer.addEventListener(TimerEvent.Timer, timerHandler);
timer.start();
var offCycle:Boolean = true;
function timerHandler(event:TimerEvent):void
{
// Do things that happen every 100 ms
if (!offCycle)
{
// Do things that happen every 200 ms
}
offCycle = !offCycle;
}

Timer.
timer Timer ,
stop() Timer, true.
enterFrame Timer
, .
.
, ,
, .
,
Flash Player AIR.
.
.

AIR (
(Arno Gourdol))


67


,
, .
, Flash- ,
.
. .

12.10.2011.

37

38

4.
ActionScript 3.0
Vector Array
Vector Array.
Vector , Array.
Vector Array.
Array.
var coordinates:Array = new Array();
var started:Number = getTimer();
for (var i:int = 0; i< 300000; i++)
{
coordinates[i] = Math.random()*1024;
}
trace(getTimer() - started);
// output: 107

Vector.
var coordinates:Vector.<Number> = new Vector.<Number>();
var started:Number = getTimer();
for (var i:int = 0; i< 300000; i++)
{
coordinates[i] = Math.random()*1024;
}
trace(getTimer() - started);
// output: 72


:
// Specify a fixed length and initialize its length
var coordinates:Vector.<Number> = new Vector.<Number>(300000, true);
var started:Number = getTimer();
for (var i:int = 0; i< 300000; i++)
{
coordinates[i] = Math.random()*1024;
}
trace(getTimer() - started);
// output: 48

12.10.2011.

FLASH PLATFORM
ActionScript 3.0

, , .
.
.
. , ,
. .
.
// Store the reused value to maintain code easily
const MAX_NUM:int = 300000;
var coordinates:Vector.<Number> = new Vector.<Number>(MAX_NUM, true);
var started:Number = getTimer();
for (var i:int = 0; i< MAX_NUM; i++)
{
coordinates[i] = Math.random()*1024;
}
trace(getTimer() - started);
// output: 47

API- Vector, .

API-
API- .
Flash Player 10 AIR 1.5 API- ,
. API-
,
.
ActionScript.
API- :

drawPath()

drawGraphicsData()

drawTriangles()

. drawTriangles(),
. ActionScript,
.
.

12.10.2011.

39

FLASH PLATFORM
ActionScript 3.0

var container:Shape = new Shape();


container.graphics.beginFill(0x442299);
var coords:Vector.<Number> = Vector.<Number>([132, 20, 46, 254, 244, 100, 20, 98, 218, 254]);
container.graphics.moveTo
container.graphics.lineTo
container.graphics.lineTo
container.graphics.lineTo
container.graphics.lineTo

(
(
(
(
(

coords[0],
coords[2],
coords[4],
coords[6],
coords[8],

coords[1]
coords[3]
coords[5]
coords[7]
coords[9]

);
);
);
);
);

addChild( container );

, ,
. ,
drawPath().
var container:Shape = new Shape();
container.graphics.beginFill(0x442299);
var commands:Vector.<int> = Vector.<int>([1,2,2,2,2]);
var coords:Vector.<Number> = Vector.<Number>([132, 20, 46, 254, 244, 100, 20, 98, 218, 254]);
container.graphics.drawPath(commands, coords);
addChild( container );

drawGraphicsData() .


.
ActionScript 3.0 , .
ActionScript.
, , .
, ,
. , .
MouseEvent.CLICK, , .

12.10.2011.

40

FLASH PLATFORM
ActionScript 3.0

const MAX_NUM:int = 10;


var sceneWidth:int = stage.stageWidth;
var sceneHeight:int = stage.stageHeight;
var currentApple:InteractiveObject;
var currentAppleClicked:InteractiveObject;
for ( var i:int = 0; i< MAX_NUM; i++ )
{
currentApple = new Apple();
currentApple.x = Math.random()*sceneWidth;
currentApple.y = Math.random()*sceneHeight;
addChild ( currentApple );
// Listen to the MouseEvent.CLICK event
currentApple.addEventListener ( MouseEvent.CLICK, onAppleClick );
}
function onAppleClick ( e:MouseEvent ):void
{
currentAppleClicked = e.currentTarget as InteractiveObject;
currentAppleClicked.removeEventListener(MouseEvent.CLICK, onAppleClick );
removeChild ( currentAppleClicked );
}

Apple addEventListener(). ,
removeEventListener() . ActionScript
3.0 ,
(InteractiveObject).
addEventListener() removeEventListener().
.
const MAX_NUM:int = 10;
var sceneWidth:int = stage.stageWidth;
var sceneHeight:int = stage.stageHeight;
var currentApple:InteractiveObject;
var currentAppleClicked:InteractiveObject;
var container:Sprite = new Sprite();
addChild ( container );
// Listen to the MouseEvent.CLICK on the apple's parent
// Passing true as third parameter catches the event during its capture phase
container.addEventListener ( MouseEvent.CLICK, onAppleClick, true );
for ( var i:int = 0; i< MAX_NUM; i++ )
{
currentApple = new Apple();
currentApple.x = Math.random()*sceneWidth;
currentApple.y = Math.random()*sceneHeight;
container.addChild ( currentApple );
}
function onAppleClick ( e:MouseEvent ):void
{
currentAppleClicked = e.target as InteractiveObject;
container.removeChild ( currentAppleClicked );
}

12.10.2011.

41

FLASH PLATFORM
ActionScript 3.0

, . addEventListener()
. Apple,
. onAppleClick()
. .
function onAppleClick ( e:MouseEvent ):void
{
e.stopPropagation();
currentAppleClicked = e.target as InteractiveObject;
container.removeChild ( currentAppleClicked );
}

.
addEventListener() false .
// Listen to the MouseEvent.CLICK on apple's parent
// Passing false as third parameter catches the event during its bubbling phase
container.addEventListener ( MouseEvent.CLICK, onAppleClick, false );

false, .
container.addEventListener ( MouseEvent.CLICK, onAppleClick );


setVector().

BitmapData.
setVector():
// Image dimensions
var wdth:int = 200;
var hght:int = 200;
var total:int = wdth*hght;
// Pixel colors Vector
var pixels:Vector.<uint> = new Vector.<uint>(total, true);
for ( var i:int = 0; i< total; i++ )
{
// Store the color of each pixel
pixels[i] = Math.random()*0xFFFFFF;
}
// Create a non-transparent BitmapData object
var myImage:BitmapData = new BitmapData ( wdth, hght, false );
var imageContainer:Bitmap = new Bitmap ( myImage );
// Paint the pixels
myImage.setVector ( myImage.rect, pixels );
addChild ( imageContainer );

12.10.2011.

42

FLASH PLATFORM
ActionScript 3.0

, setPixel() setPixel32(),
lock() unlock() . lock() unlock()
.
var
var
var
var

buffer:BitmapData = new BitmapData(200,200,true,0xFFFFFFFF);


bitmapContainer:Bitmap = new Bitmap(buffer);
positionX:int;
positionY:int;

// Lock update
buffer.lock();
var starting:Number=getTimer();
for (var i:int = 0; i<2000000; i++)
{
// Random positions
positionX = Math.random()*200;
positionY = Math.random()*200;
// 40% transparent pixels
buffer.setPixel32( positionX, positionY, 0x66990000 );
}
// Unlock update
buffer.unlock();
addChild( bitmapContainer );
trace( getTimer () - starting );
// output : 670

lock() BitmapData ,
, BitmapData. , Bitmap
BitmapData, BitmapData, ,
. Bitmap , BitmapData .
, unlock()
setPixel() setPixel32(). lock() unlock()
.
. ,
( ), .
, lock() unlock()
. Flash Player , ,
.
, getPixel(), getPixel32(), setPixel() setPixel32(),
, . ,
. getVector(),
getPixels(). , API-,
Vector, .



String, indexOf(), substr() substring().

12.10.2011.

43

FLASH PLATFORM
ActionScript 3.0

, ,
String. , , ,
String.indexOf().
String,
.
((?:xxxx)) ((xxxx)),
, .
. ,
ab
. , + , .
/(ab)+/

.
. -

. ,
. ,
, .
/(?:ab)+/


.
,
.

.
. , - ,
, ,
. ,
.


TextField appendText() +=.
text TextField appendText() +=.
appendText() .
+=, 1120 .

12.10.2011.

44

FLASH PLATFORM
ActionScript 3.0

addChild ( myTextField );
myTextField.autoSize = TextFieldAutoSize.LEFT;
var started:Number = getTimer();
for (var i:int = 0; i< 1500; i++ )
{
myTextField.text += "ActionScript 3";
}
trace( getTimer() - started );
// output : 1120

+= appendText().
var myTextField:TextField = new TextField();
addChild ( myTextField );
myTextField.autoSize = TextFieldAutoSize.LEFT;
var started:Number = getTimer();
for (var i:int = 0; i< 1500; i++ )
{
myTextField.appendText ( "ActionScript 3" );
}
trace( getTimer() - started );
// output : 847

847 .
.
.
.

. 2 .
var myTextField:TextField = new TextField();
addChild ( myTextField );
myTextField.autoSize = TextFieldAutoSize.LEFT;
var started:Number = getTimer();
var content:String = myTextField.text;
for (var i:int = 0; i< 1500; i++ )
{
content += "ActionScript 3";
}
myTextField.text = content;
trace( getTimer() - started );
// output : 2

12.10.2011.

45

FLASH PLATFORM
ActionScript 3.0

HTML ,
Timeout Flash Player. , ,
.
. Adobe AIR .
var myTextField:TextField = new TextField();
addChild ( myTextField );
myTextField.autoSize = TextFieldAutoSize.LEFT;
var started:Number = getTimer();
for (var i:int = 0; i< 1500; i++ )
{
myTextField.htmlText += "ActionScript <b>2</b>";
}
trace( getTimer() - started );

29 .
var myTextField:TextField = new TextField();
addChild ( myTextField );
myTextField.autoSize = TextFieldAutoSize.LEFT;
var started:Number = getTimer();
var content:String = myTextField.htmlText;
for (var i:int = 0; i< 1500; i++ )
{
content += "<b>ActionScript<b> 3";
}
myTextField.htmlText = content;
trace ( getTimer() - started );
// output : 29

. Flash Player 10.1 AIR 2.5 String,


.
.
.
.
.

12.10.2011.

46

FLASH PLATFORM
ActionScript 3.0

var lng:int = 5000;


var arraySprite:Vector.<Sprite> = new Vector.<Sprite>(lng, true);
var i:int;
for ( i = 0; i< lng; i++ )
{
arraySprite[i] = new Sprite();
}
var started:Number = getTimer();
for ( i = 0; i< lng; i++ )
{
arraySprite[i].x = Math.random()*stage.stageWidth;
arraySprite[i].y = Math.random()*stage.stageHeight;
arraySprite[i].alpha = Math.random();
arraySprite[i].rotation = Math.random()*360;
}
trace( getTimer() - started );
// output : 16


.
var lng:int = 5000;
var arraySprite:Vector.<Sprite> = new Vector.<Sprite>(lng, true);
var i:int;
for ( i = 0; i< lng; i++ )
{
arraySprite[i] = new Sprite();
}
var started:Number = getTimer();
var currentSprite:Sprite;
for ( i = 0; i< lng; i++ )
{
currentSprite = arraySprite[i];
currentSprite.x = Math.random()*stage.stageWidth;
currentSprite.y = Math.random()*stage.stageHeight;
currentSprite.alpha = Math.random();
currentSprite.rotation = Math.random()*360;
}
trace( getTimer() - started );
// output : 9

12.10.2011.

47

FLASH PLATFORM
ActionScript 3.0

.
.
. ,
SWF-. ,
Math, . Math.abs()
.
const MAX_NUM:int = 500000;
var arrayValues:Vector.<Number>=new Vector.<Number>(MAX_NUM,true);
var i:int;
for (i = 0; i< MAX_NUM; i++)
{
arrayValues[i] = Math.random()-Math.random();
}
var started:Number = getTimer();
var currentValue:Number;
for (i = 0; i< MAX_NUM; i++)
{
currentValue = arrayValues[i];
arrayValues[i] = Math.abs ( currentValue );
}
trace( getTimer() - started );
// output : 70

Math.abs() .
const MAX_NUM:int = 500000;
var arrayValues:Vector.<Number>=new Vector.<Number>(MAX_NUM,true);
var i:int;
for (i = 0; i< MAX_NUM; i++)
{
arrayValues[i] = Math.random()-Math.random();
}
var started:Number = getTimer();
var currentValue:Number;
for (i = 0; i< MAX_NUM; i++)
{
currentValue = arrayValues[i];
arrayValues[i] = currentValue > 0 ? currentValue : -currentValue;
}
trace( getTimer() - started );
// output : 15

, .
, ,
.

12.10.2011.

48

FLASH PLATFORM
ActionScript 3.0

. .
ActionScript,
JIT-. -
- , .
Adobe Flex, TLF
ActionScript .
.
.
, ,
.
for (var i:int = 0; i< myArray.length; i++)
{
}

.
var lng:int = myArray.length;
for (var i:int = 0; i< lng; i++)
{
}

while.
while , .
var i:int = myArray.length;
while (--i > -1)
{
}

ActionScript, ,
.
ActionScript. .
http://www.rozengain.com/blog/2007/05/01/some-actionscript-30-optimizations/.

12.10.2011.

49

50

5.


.

. ,
Flash Player. ,
Flash Player.
. Adobe AIR
Flash Player ( Adobe AIR ,
, ).

:


flash.profiler.showRedrawRegions():
// Enable Show Redraw Regions
// Blue color is used to show redrawn regions
flash.profiler.showRedrawRegions ( true, 0x0000FF );

Adobe AIR .

12.10.2011.

FLASH PLATFORM

. ,
, - ,
. .
. , ,
-.
:

visible
false . .
, .
.
-
.


29


.
.
.

.
.

12.10.2011.

51

FLASH PLATFORM

,
, .
,
, . ,

.

12.10.2011.

52

FLASH PLATFORM

, ,
, .

.
.

StageQuality.LOW:

. Adobe AIR .

StageQuality.MEDIUM: ,
. AIR ,
AIR -.

StageQuality.HIGH:
( ). SWF-
, .
.

StageQuality.BEST: , .
, .

StageQuality.MEDIUM
,
StageQuality.LOW. Flash Player 8,
, LOW.
. , HIGH,
Flash Player MEDIUM.
HIGH ,
. ( .)
MEDIUM,
.

- ,
.
.
( )
.

12.10.2011.

53

FLASH PLATFORM


( ).

( )

,
. Flash Player 8
. , Flash Player 10.1
StageQuality.MEDIUM .

-
alpha.
-, ,
alpha. -,

. , -
, .
.
alpha.

12.10.2011.

54

FLASH PLATFORM


57
70


: .

,
1. . ,
,
. ,
.

.

Flex
.

, 20
. , 30 , .

, , , 12 .
.
. .
,
.
,
.
,
.
.
,
. Flex
Stage.frameRate ( WindowedApplication.frameRate).
. ,
, . ,
. , (
), . ,
.

12.10.2011.

55

FLASH PLATFORM

,
.

Flex
.

20 .
, 30 , .

, , , 12
.

,
. ,
, 12 .

, , 5 .
AIR , 2
. , , .
, visible false.
, Flex; spark. WindowedApplication
.
backgroundFrameRate. 1,
, Spark, 1 .
, backgroundFrameRate.
-1, .
. .

Adobe AIR ( Adobe Developer Center,


(Jonnie Hallman))

AIR (
(Arno Gourdol))
(Grant Skinner) .

. FramerateThrottler
Adobe AIR Flash Player
http://gskinner.com/blog/archives/2009/05/idle_cpu_usage.html.


SWF- .

.
.
.
. ,
. - ,
. , ,
,
.

12.10.2011.

56

FLASH PLATFORM


,
.
.
,
.
,
.
, .
,
, . ,
, ,
, .
, ,
.
,
.
,
. x y
. , ,
-,
, .
. DisplayObject.cacheAsBitmapMatrix, AIR
Packager for iPhone, . cacheAsBitmapMatrix,
, , -
.
,
. , 250 x 250 ,
250 ( 1 ).
Sprite, .
.

12.10.2011.

57

FLASH PLATFORM

package org.bytearray.bitmap
{
import flash.display.Sprite;
import flash.events.Event;
public class Apple extends Sprite
{
private var destinationX:Number;
private var destinationY:Number;
public function Apple ()
{
addEventListener(Event.ADDED_TO_STAGE,activation);
addEventListener(Event.REMOVED_FROM_STAGE,deactivation);
}
private function activation(e:Event):void
{
initPos();
addEventListener (Event.ENTER_FRAME,handleMovement);
}
private function deactivation(e:Event):void
{
removeEventListener(Event.ENTER_FRAME,handleMovement);
}
private function initPos():void
{
destinationX = Math.random()*(stage.stageWidth - (width>>1));
destinationY = Math.random()*(stage.stageHeight - (height>>1));
}
private function handleMovement(e:Event):void
{
x -= (x - destinationX)*.5;
y -= (y - destinationY)*.5;
if (Math.abs(x - destinationX) < 1 && Math.abs(y - destinationY) < 1)
initPos();
}
}
}

MovieClip Sprite,
.
. .

12.10.2011.

58

FLASH PLATFORM

import org.bytearray.bitmap.Apple;
stage.addEventListener(MouseEvent.CLICK,createApples);
stage.addEventListener(KeyboardEvent.KEY_DOWN,cacheApples);
const MAX_NUM:int = 100;
var apple:Apple;
var holder:Sprite = new Sprite();
addChild(holder);
function createApples(e:MouseEvent):void
{
for (var i:int = 0; i< MAX_NUM; i++)
{
apple = new Apple();
holder.addChild(apple);
}
}
function cacheApples(e:KeyboardEvent):void
{
if (e.keyCode == 67)
{
var lng:int = holder.numChildren;
for (var i:int = 0; i < lng; i++)
{
apple = holder.getChildAt (i) as Apple;
apple.cacheAsBitmap = Boolean(!apple.cacheAsBitmap);
}
}
}

, .
C ( 67),
.
,
.

, .

, .

12.10.2011.

59

FLASH PLATFORM

cacheAsBitmap = true

Flash Player 10.1 AIR 2.5 ,


20.
, , , , .
. opaqueBackground ,
. cacheAsBitmap
32- . -
0xFF, ,
. -
. 16 ,
16- . opaqueBackground
.
cacheAsBitmap
, .
,
211 x 279 . 229 :

211

279

12.10.2011.

60

FLASH PLATFORM

, - ,
.
7 ,
42 :

getChildAt()
Vector .

12.10.2011.

61

FLASH PLATFORM

import org.bytearray.bitmap.Apple;
stage.addEventListener(KeyboardEvent.KEY_DOWN, cacheApples);
const MAX_NUM:int = 200;
var apple:Apple;
var holder:Sprite = new Sprite();
addChild(holder);
var holderVector:Vector.<Apple> = new Vector.<Apple>(MAX_NUM, true);
for (var i:int = 0; i< MAX_NUM; i++)
{
apple = new Apple();
holder.addChild(apple);
holderVector[i] = apple;
}
function cacheApples(e:KeyboardEvent):void
{
if (e.keyCode == 67)
{
var lng:int = holderVector.length
for (var i:int = 0; i < lng; i++)
{
apple = holderVector[i];
apple.cacheAsBitmap = Boolean(!apple.cacheAsBitmap);
}
}
}

, ,
, . ,
X Y, .
Flash Player
. ,
.
cacheAsBitmapMatrix, AIR Packager for
iPhone.
- ,
.
private function handleMovement(e:Event):void
{
alpha = Math.random();
x -= (x - destinationX)*.5;
y -= (y - destinationY)*.5;
if (Math.abs(x - destinationX) < 1 && Math.abs(y - destinationY) < 1)
initPos();
}

12.10.2011.

62

FLASH PLATFORM

.
-
.
,
. cacheAsBitmap
true. .

,
. .

, (. . ),
. , ,
, x y.
,
,
.
(Paul Trani) Flash Professional ActionScript
:


ActionScript

AIR
AIR
cacheAsBitmapMatrix.

12.10.2011.

63

FLASH PLATFORM

AIR cacheAsBitmapMatrix
.
. alpha
. cacheAsBitmap
true, 3D.
cacheAsBitmapMatrix ,
, visible,
false. cacheAsBitmapMatrix
, ,
.
, cacheAsBitmapMatrix,
, . ,
,
.
, .
,
, . ,
,
. ,
, ,
.
displayObject.cacheAsBitMap = true;
displayObject.cacheAsBitmapMatrix = new Matrix();

cacheAsBitmapMatrix
, , .
- 0 1. -
transform.colorTransform , , , 0 255.

.
, , cacheAsBitmap
true, cacheAsBitmapMatrix.
. ,
,
.


BitmapData
.

BitmapData.
BitmapData .
.
.

12.10.2011.

64

FLASH PLATFORM

BitmapApple.
package org.bytearray.bitmap
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.events.Event;
public class BitmapApple extends Bitmap
{
private var destinationX:Number;
private var destinationY:Number;
public function BitmapApple(buffer:BitmapData)
{
super(buffer);
addEventListener(Event.ADDED_TO_STAGE,activation);
addEventListener(Event.REMOVED_FROM_STAGE,deactivation);
}
private function activation(e:Event):void
{
initPos();
addEventListener(Event.ENTER_FRAME,handleMovement);
}
private function deactivation(e:Event):void
{
removeEventListener(Event.ENTER_FRAME,handleMovement);
}
private function initPos():void
{
destinationX = Math.random()*(stage.stageWidth - (width>>1));
destinationY = Math.random()*(stage.stageHeight - (height>>1));
}
private function handleMovement(e:Event):void
{
alpha = Math.random();
x -= (x - destinationX)*.5;
y -= (y - destinationY)*.5;
if ( Math.abs(x - destinationX) < 1 && Math.abs(y - destinationY) < 1)
initPos();
}
}
}

- .
BitmapApple.

12.10.2011.

65

FLASH PLATFORM

import org.bytearray.bitmap.BitmapApple;
const MAX_NUM:int = 100;
var holder:Sprite = new Sprite();
addChild(holder);
var holderVector:Vector.<BitmapApple> = new Vector.<BitmapApple>(MAX_NUM, true);
var source:AppleSource = new AppleSource();
var bounds:Object = source.getBounds(source);
var mat:Matrix = new Matrix();
mat.translate(-bounds.x,-bounds.y);
var buffer:BitmapData = new BitmapData(source.width+1, source.height+1, true, 0);
buffer.draw(source,mat);
var bitmapApple:BitmapApple;
for (var i:int = 0; i< MAX_NUM; i++)
{
bitmapApple = new BitmapApple(buffer);
holderVector[i] = bitmapApple;
holder.addChild(bitmapApple);
}

,
, BitmapApple. ,
, BitmapApple, -,
, .
.
smoothing true:
public function BitmapApple(buffer:BitmapData)
{
super (buffer);
smoothing = true;
addEventListener(Event.ADDED_TO_STAGE, activation);
addEventListener(Event.REMOVED_FROM_STAGE, deactivation);
}

.
HIGH , LOW.

12.10.2011.

66

FLASH PLATFORM

import org.bytearray.bitmap.BitmapApple;
const MAX_NUM:int = 100;
var holder:Sprite = new Sprite();
addChild ( holder );
var holderVector:Vector.<BitmapApple> = new Vector.<BitmapApple>(MAX_NUM, true);
var source:AppleSource = new AppleSource();
var bounds:Object = source.getBounds ( source );
var mat:Matrix = new Matrix();
mat.translate ( -bounds.x, -bounds.y );
var buffer:BitmapData = new BitmapData ( source.width+1, source.height+1, true, 0 );
stage.quality = StageQuality.HIGH;
buffer.draw ( source, mat );
stage.quality = StageQuality.LOW;
var bitmapApple:BitmapApple;
for (var i:int = 0; i< MAX_NUM; i++ )
{
bitmapApple = new BitmapApple( buffer );
holderVector[i] = bitmapApple;
holder.addChild ( bitmapApple );
}


.
. ,
, LOW.
cacheAsBitmap. LOW
,
.


, Event.ENTER_FRAME, .
Event.ENTER_FRAME Apple
. . , BitmapApple
.

12.10.2011.

67

FLASH PLATFORM

package org.bytearray.bitmap
{
import flash.display.Bitmap;
import flash.display.BitmapData;
public class BitmapApple extends Bitmap
{
private var destinationX:Number;
private var destinationY:Number;
public function BitmapApple(buffer:BitmapData)
{
super (buffer);
smoothing = true;
}
}

, ,
.
import org.bytearray.bitmap.BitmapApple;
const MAX_NUM:int = 100;
var holder:Sprite = new Sprite();
addChild(holder);
var holderVector:Vector.<BitmapApple> = new Vector.<BitmapApple>(MAX_NUM, true);
var source:AppleSource = new AppleSource();
var bounds:Object = source.getBounds(source);
var mat:Matrix = new Matrix();
mat.translate(-bounds.x,-bounds.y);
stage.quality = StageQuality.BEST;
var buffer:BitmapData = new BitmapData(source.width+1,source.height+1, true,0);
buffer.draw(source,mat);
stage.quality = StageQuality.LOW;
var bitmapApple:BitmapApple;
for (var i:int = 0; i< MAX_NUM; i++)
{
bitmapApple = new BitmapApple(buffer);
bitmapApple.destinationX = Math.random()*stage.stageWidth;
bitmapApple.destinationY = Math.random()*stage.stageHeight;
holderVector[i] = bitmapApple;
holder.addChild(bitmapApple);
}
stage.addEventListener(Event.ENTER_FRAME,onFrame);

12.10.2011.

68

FLASH PLATFORM

var lng:int = holderVector.length


function onFrame(e:Event):void
{
for (var i:int = 0; i < lng; i++)
{
bitmapApple = holderVector[i];
bitmapApple.alpha = Math.random();
bitmapApple.x -= (bitmapApple.x - bitmapApple.destinationX) *.5;
bitmapApple.y -= (bitmapApple.y - bitmapApple.destinationY) *.5;
if (Math.abs(bitmapApple.x - bitmapApple.destinationX ) < 1 &&
Math.abs(bitmapApple.y - bitmapApple.destinationY ) < 1)
{
bitmapApple.destinationX = Math.random()*stage.stageWidth;
bitmapApple.destinationY = Math.random()*stage.stageHeight;
}
}
}

Event.ENTER_FRAME
200 . ,
.
, .
stage.addEventListener(Event.ENTER_FRAME, updateGame);
function updateGame (e:Event):void
{
gameEngine.update();
}

, .
BitmapApple.

12.10.2011.

69

FLASH PLATFORM

package org.bytearray.bitmap
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
public class BitmapApple extends Sprite
{
public var destinationX:Number;
public var destinationY:Number;
private var container:Sprite;
private var containerBitmap:Bitmap;
public function BitmapApple(buffer:BitmapData)
{
container = new Sprite();
containerBitmap = new Bitmap(buffer);
containerBitmap.smoothing = true;
container.addChild(containerBitmap);
addChild(container);
}
}

BitmapApple, Sprite.
,
.


opaqueBackground
.
Flash Text Engine .
.
TextLine
ActionScript. TextLine
, .

.
, ,
.
,
opaqueBackground .
, ,
.

12.10.2011.

70

FLASH PLATFORM

, TextField
. .

12.10.2011.

71

FLASH PLATFORM

. preloader ,
, .
wait_mc.addEventListener( Event.ENTER_FRAME, movePosition );
var destX:Number=stage.stageWidth/2;
var destY:Number=stage.stageHeight/2;
var preloader:DisplayObject;
function movePosition( e:Event ):void
{
preloader = e.currentTarget as DisplayObject;
preloader.x -= ( preloader.x - destX ) * .1;
preloader.y -= ( preloader.y - destY ) * .1;
if (Math.abs(preloader.y-destY)<1)
preloader.removeEventListener( Event.ENTER_FRAME, movePosition );
}

12.10.2011.

72

FLASH PLATFORM

Math.abs()
. int destX destY
. int
,
Math.ceil() Math.round(). ,
.
, .
. .
// Do not use this code
var destX:Number = Math.round ( stage.stageWidth / 2 );
var destY:Number = Math.round ( stage.stageHeight / 2);

.
var destX:int = stage.stageWidth / 2;
var destY:int = stage.stageHeight / 2;


.
var destX:int = stage.stageWidth >> 1;
var destY:int = stage.stageHeight >> 1;


.
, TextField.
wait_mc.cacheAsBitmap = true;

. -
, .
opaqueBackground .
opaqueBackground ,
, - 32 . 255
. opaqueBackground
,
.
.

12.10.2011.

73

FLASH PLATFORM

wait_mc.addEventListener( Event.ENTER_FRAME, movePosition );


wait_mc.cacheAsBitmap = true;
// Set the background to the color of the scene background
wait_mc.opaqueBackground = 0x8AD6FD;
var destX:int = stage.stageWidth >> 1;
var destY:int = stage.stageHeight >> 1;
var preloader:DisplayObject;
function movePosition ( e:Event ):void
{
preloader = e.currentTarget as DisplayObject;
preloader.x -= ( preloader.x - destX ) * .1;
preloader.y -= ( preloader.y - destY ) * .1;
if ( Math.abs ( preloader.y - destY ) < 1 )
e.currentTarget.removeEventListener ( Event.ENTER_FRAME, movePosition );
}

,
.
LOW HIGH
.
wait_mc.addEventListener( Event.ENTER_FRAME, movePosition );
wait_mc.cacheAsBitmap = true;
wait_mc.opaqueBackground = 0x8AD6FD;
// Switch to low quality
stage.quality = StageQuality.LOW;
var destX:int = stage.stageWidth>>1;
var destY:int = stage.stageHeight>>1;
var preloader:DisplayObject;
function movePosition( e:Event ):void
{
preloader = e.currentTarget as DisplayObject;
preloader.x -= ( preloader.x - destX ) * .1;
preloader.y -= ( preloader.y - destY ) * .1;
if (Math.abs(e.currentTarget.y-destY)<1)
{
// Switch back to high quality
stage.quality = StageQuality.HIGH;
preloader.removeEventListener( Event.ENTER_FRAME, movePosition );
}
}


TextField .

.

12.10.2011.

74

FLASH PLATFORM

, .
opaqueBackground
BitmapData,
.
, . ,
, . ,
, ,
.
,
. ,
.
BitmapData.draw() .
, Flash Player 8 ( AIR 1.0)
,
. ,

.
.
wait_mc.addEventListener( Event.ENTER_FRAME, movePosition );
// Switch to low quality
stage.quality = StageQuality.LOW;
var destX:int = stage.stageWidth >> 1;
var destY:int = stage.stageHeight >> 1;
var preloader:DisplayObject;
function movePosition ( e:Event ):void
{
preloader = e.currentTarget as DisplayObject;
preloader.x -= ( preloader.x - destX ) * .1;
preloader.y -= ( preloader.y - destY ) * .1;
if ( Math.abs ( preloader.y - destY ) < 1 )
{
// Switch back to high quality
stage.quality = StageQuality.HIGH;
preloader.removeEventListener ( Event.ENTER_FRAME, movePosition );
}
}

( ) .
,
. ,
,
LOW. HIGH.

12.10.2011.

75

FLASH PLATFORM


Flash
Player
Flash Player 10.1 ,
.
. ,
, . ,
, .
. , Flash Player 10.1
Pixel Bender .
.
Flash Player 10 ,
.
. Flash Player 10.1 ,
. ,
, .

. wmode gpu
, wmode opaque
transparent, .
. Flash Player -
. ,
,
. ,
.

AIR

AIR
<renderMode>gpu</renderMode> .
. renderMode .
.

AIR 2.5
.

, .
.

: , , , , ,
.

.
PixelBender .

12.10.2011.

76

FLASH PLATFORM

1024 x 1024.
ActionScript
.

Adobe
AIR .


, . ,
, .
, .

,
. AIR
.

.

.
, . ,
visible false.
, alpha 0.
,
removeChild().

, .
, , 2n 2m .
2, ,
. , 31 15 , 33 17
. (31 15 2: 32 16.)

, repeat false Graphic.beginBitmapFill().


. .
. .

, ,
. ,
.

.
cacheAsBitMap cacheAsBitmapMatrix, ,
.

API- ActionScript ( Graphics) .


.

,
.

12.10.2011.

77

FLASH PLATFORM

AIR 2.0.3

AIR ,
Packager for iPhone, .
, ,
cacheAsBitmap. cacheAsBitmap,
cacheAsBitmapMatrix,
.
, .




SWF, . , ,
,
. ,

.
. , ,
SWF . SWF
, .

wmode=transparent wmode=opaque
HTML. . ,
,
.
, , .

-.
, .
.

,
, . .
, ,
.
, .

, (,
) .
, .
, : 500 500 100 10.
,
. .
, .

,
.

12.10.2011.

78

FLASH PLATFORM

.
, .
.

.
,
. ,
,
.
, ,
.
,
.
, .

.
Stage.

,
.
.


.
, .
, .
, ,
.
.
.
, .
.
,
.
, .
,
. .
3.
.
, , .

12.10.2011.

79

FLASH PLATFORM


. Adobe AIR ,
.

File FileStream
File . ,
, ,
, . Async,
. , ,
File.deleteFile File.deleteFileAsync().
FileStream
FileStream .
FileStream.openAsync().
. ,
. , FileStream ,
.

SQL
SQL SQLConnection
, .
, , SQLConnection.openAsync()
SQLConnection.open(). .
, ,
.
SQL .
SQL 94.

Pixel Bender
ShaderJob Pixel Bender
. ShaderJob.start()
.
. ShaderJob ( ),
start() true.

.
, . ,

, .
. ,
.
.
Timer.
.
, ,
.

ActionScript ( ,
, (Trevor McCauley))

12.10.2011.

80

FLASH PLATFORM

Flash Player (
: Builder ,
(Jesse Warden))

(
, (Drew Cummins))

greenthreads ( , ActionScript,
(Charlie Hubbard)). . -
.)

ActionScript 3: http://www.adobe.com/go/learn_fp_as3_threads_ru ( (Alex


Harui) )


AIR
.
AIR ,
XML- :
<initialWindow>
<transparent>false</transparent>
</initialWindow>

, , NativeWindowInitOptions
transparent false ( ). NativeWindow
NativeWindow:
// NativeWindow: flash.display.NativeWindow class
var initOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
initOptions.transparent = false;
var win:NativeWindow = new NativeWindow(initOptions);

Flex Window open() Window ,


transparent false ( ).
// Flex window component: spark.components.Window class
var win:Window = new Window();
win.transparent = false;
win.open();


, . ,
. ,
Chrome, .
, ,
.

12.10.2011.

81

FLASH PLATFORM


.

, ,
. .
:

Flash Professional .
Adobe Illustrator.
.
SWF-
. :

12.10.2011.

82

FLASH PLATFORM

, .

.

12.10.2011.

83

84

6.

Flash Player 10.1 AIR 2.5 ,


,
.


,
. ,
, . Flash
Player 10.1 AIR 2.5 FLV- ( MP 4-) .
.
. ,
.
.
, ,
. ,
. .
, , .
. ,
, .
, 4
20 .
. ,
. ,
, .
.
MP4- ,
. ,
, MP4- .
.
, .
NetStream.seek(), ,
NetStream.Seek.InvalidTime.


. Adobe Flash Media Server
3.5.3.

12.10.2011.

FLASH PLATFORM

Flash Player 10.1 AIR 2.5 ,


,
. ,
.
. ,
20 (NetStream.bufferTime), 10

10 .
.
, .
bufferTime ,
:


, .
.

,
, .
. ,
,
.
. .
, NetStream.inBufferSeek true.

12.10.2011.

85

FLASH PLATFORM


SWF-.
.
SWF-.
. , ,
SWF-, .
portfolio.swf

infos.swf

contact.swf

10

10

10

main.swf

10

preload.swf

40
, SWF-

SWF- .
,
.
portfolio.swf

infos.swf

contact.swf

main.swf

preload.swf

library.swf

10
10

12.10.2011.

86

FLASH PLATFORM

,
SWF-. ApplicationDomain
getDefinition().
.
.
, SWF-,
. , ,
ActionScript.
// Create a Loader object
var loader:Loader = new Loader();
// Listen to the Event.COMPLETE event
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadingComplete );
// Load the SWF file
loader.load(new URLRequest("library.swf") );
var classDefinition:String = "Logo";
function loadingComplete(e:Event ):void
{
var objectLoaderInfo:LoaderInfo = LoaderInfo ( e.target );
// Get a reference to the loaded SWF file application domain
var appDomain:ApplicationDomain = objectLoaderInfo.applicationDomain;
// Check whether the definition is available
if ( appDomain.hasDefinition(classDefinition) )
{
// Extract definition
var importLogo:Class = Class ( appDomain.getDefinition(classDefinition) );
// Instantiate logo
var instanceLogo:BitmapData = new importLogo(0,0);
// Add it to the display list
addChild ( new Bitmap ( instanceLogo ) );
} else trace ("The class definition " + classDefinition + " is not available.");
}


SWF-:

12.10.2011.

87

FLASH PLATFORM

// Create a Loader object


var loader:Loader = new Loader();
// Listen to the Event.COMPLETE event
loader.contentLoaderInfo.addEventListener ( Event.COMPLETE, loadingComplete );
// Load the SWF file
loader.load ( new URLRequest ("rsl.swf"), new LoaderContext ( false,
ApplicationDomain.currentDomain) );
var classDefinition:String = "Logo";
function loadingComplete ( e:Event ):void
{
var objectLoaderInfo:LoaderInfo = LoaderInfo ( e.target );
// Get a reference to the current SWF file application domain
var appDomain:ApplicationDomain = ApplicationDomain.currentDomain;
// Check whether the definition is available
if (appDomain.hasDefinition( classDefinition ) )
{
// Extract definition
var importLogo:Class = Class ( appDomain.getDefinition(classDefinition) );
// Instantiate it
var instanceLogo:BitmapData = new importLogo(0,0);
// Add it to the display list
addChild ( new Bitmap ( instanceLogo ) );
} else trace ("The class definition " + classDefinition + " is not available.");
}

, SWF-, , getDefinition()
.
getDefinitionByName().
.
SWF-. ,
loader.swf. , SWF, .

-
-.
,
.
: . ,
, IO_ERROR
.

12.10.2011.

88

FLASH PLATFORM

, -
.
.
, .

.
-. , .
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener( Event.COMPLETE, onComplete );
addChild( loader );
loader.load( new URLRequest ("asset.swf" ) );
function onComplete( e:Event ):void
{
var loader:Loader = e.currentTarget.loader;
loader.x = ( stage.stageWidth - e.currentTarget.width ) >> 1;
loader.y = ( stage.stageHeight - e.currentTarget.height ) >> 1;
}

.
.
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener ( Event.COMPLETE, onComplete );
loader.contentLoaderInfo.addEventListener ( IOErrorEvent.IO_ERROR, onIOError );
addChild ( loader );
loader.load ( new URLRequest ("asset.swf" ) );
function onComplete ( e:Event ):void
{
var loader:Loader = e.currentTarget.loader;
loader.x = ( stage.stageWidth - e.currentTarget.width ) >> 1;
loader.y = ( stage.stageHeight - e.currentTarget.height ) >> 1;
}
function onIOError ( e:IOErrorEvent ):void
{
// Show a message explaining the situation and try to reload the asset.
// If it fails again, ask the user to retry when the connection will be restored
}

.
onIOError().

Flash Remoting
Flash Remoting
AMF.

12.10.2011.

89

FLASH PLATFORM

XML SWF-. XML


, . XML
, . ,
, Flash
Remoting Action Message Format (AMF).
AMF ,
. AMF . AMF
,
AMF .
. ActionScript
. .
, , .
Flash Remoting ZendAMF, FluorineFX, WebORB BlazeDS, Java
Flash Remoting Adobe.
Flash Remoting.
ZendAMF
HTTP

Web ORB
RubyAMF

AMF

FluorineFX

( PHP,
Java, C# ...)

BlazeDS

Flash Remoting

NetConnection Flash Remoting.


// Create the NetConnection object
var connection:NetConnection = new NetConnection ();
// Connect to a Flash Remoting gateway
connection.connect ("http://www.yourserver.com/remotingservice/gateway.php");
// Asynchronous handlers for incoming data and errors
function success ( incomingData:* ):void
{
trace( incomingData );
}
function error ( error:* ):void
{
trace( "Error occured" );
}
// Create an object that handles the mapping to success and error handlers
var serverResult:Responder = new Responder (success, error);
// Call the remote method
connection.call ("org.yourserver.HelloWorld.sayHello", serverResult, "Hello there ?");

. Flash Remoting
RemoteObject, Adobe Flex SDK.

12.10.2011.

90

FLASH PLATFORM

. SWC-, Flex, Adobe


Flash Professional. SWC- RemoteObject
Flex SDK.

Socket.


,
.
, ,
. ,
. , ,
.
.

, : ,
File FileStream

:
, SharedObject

:

ResourceCache AS3CoreLib
.

12.10.2011.

91

92

7.

.
- - Adobe Developer Connection.
, :

StageVideo
StageVideo
.
StageVideo . StageVideo
ActionScript 3.0.

Flash Player 9.0.115.0 AIR 1.0, AAC-


(AAC Main, AAC LC SBR). AAC- MP3-
. AAC
, MP3. , ,

.


, ,
. Flash Player 10.1 AIR 2.5
AAC (LC, HE/SBR-) MP3- (PCM ).
, , ,
.

12.10.2011.

FLASH PLATFORM

. AAC AAC Main


- .
, .
, , .
,
. , AAC MP3
, . ,
.

12.10.2011.

93

94

8.
SQL

text SQLStatement .
SQLStatement SQL
.
SQL (),
. SQLStatement.execute()
SQLStatement, ,
. execute(), SQLStatement.text
, . , .

,
. (
SQLStatement.parameters.) text SQLStatement,
.
SQLStatement
SQLStatement.
, .
, SQL .
, , .
( .)
, -
. , SQLStatement,
, . , SQLStatement
ActionScript , ,
JavaScript. execute()
.
.
.
.
(, )
ORDER BY.

12.10.2011.

FLASH PLATFORM
SQL

, -
(INSERT UPDATE) .
. -
. .
:

, WHERE ORDER BY
,
, ,
COLLATE NOCASE
SQL .
SQL ,
() SQL.
,
:
1 .
2

.
,
. ,
. SQLStatement .
, ,
- . SQLStatement .
SQLStatement
.
, SQLStatement ,
, . ,
.
SQL .
, SQL,
( INSERT UPDATE). ,
. ,
.
( )
.
, ,
. ,
. , ,
. ,
SQL.
SELECT , execute()
SQLStatement ( prefetch) next().

12.10.2011.

95

FLASH PLATFORM
SQL

, SQL .
. ,
. ,
, .
, 79. API-
SQL .
execute() SQLStatement prefetch ( ).
,
:
dbStatement.addEventListener(SQLEvent.RESULT, resultHandler);
dbStatement.execute(100); // 100 rows maximum returned in the first set

next()
. execute(), next()
prefetch :
// This method is called when the execute() or next() method completes
function resultHandler(event:SQLEvent):void
{
var result:SQLResult = dbStatement.getResult();
if (result != null)
{
var numRows:int = result.data.length;
for (var i:int = 0; i < numRows; i++)
{
// Process the result data
}
if (!result.complete)
{
dbStatement.next(100);
}
}
}

next() , .
, . complete SQLResult,
execute() next().
. prefetch next()
. .
,
LIMIT SELECT. ,
prefetch next() .
SQLConnection
.
SQLConnection openAsync()
, .
SQLConnection .
SQLConnection SQL .

12.10.2011.

96

FLASH PLATFORM
SQL

. ,
SQLStatement .
,
( ). ,
.
, SQLStatement SQLConnection,
SQLStatement .
, SQLStatement ,
SQLConnection.
SQLConnection, ,
, .
, , ,
.
(Paul Robertson) ,
SQLConnection,
. SQLConnection
SQLStatement. SQLStatement,
SQLConnection .
-
http://probertson.com/projects/air-sqlite/.


.
( ) .
, .
.
.
. ,
.
,
. ,
.
SQLConnection.compact()
.
, SQLConnection.compact()
. ,
, . compact() ,
.

12.10.2011.

97

FLASH PLATFORM
SQL

SQL ( ).
. (
main, .) , main
:
SELECT employeeId
FROM main.employees


.
. , SQLConnection
, SQLConnection ,
SQL.
SQL INSERT SELECT .
:
INSERT INTO main.employees (firstName, lastName, salary)
VALUES ("Bob", "Jones", 2000)
SELECT employeeId, lastName, firstName, salary
FROM main.employees

. :
-- bad because column names aren't specified
INSERT INTO main.employees
VALUES ("Bob", "Jones", 2000)
-- bad because it uses a wildcard
SELECT *
FROM main.employees

,
. SELECT
, .
, .
,
.
SQL ,
. ,
.
. ,
, , .
.

12.10.2011.

98

FLASH PLATFORM
SQL

SQL
JOIN ( FROM)
WHERE. ,
, .
FROM ,
WHERE.
SQL, .
, UNION
ORDER BY UNION.
SELECT.
SQL ,
.
LIKE, ,
LIKE('%XXXX%').
LIKE ,
, . ,
,
. .
IN. ,
, IN AND OR.
. -
, OR, IN() NOT IN():
-- Slower
SELECT lastName, firstName, salary
FROM main.employees
WHERE salary IN (2000, 2500)
-- Faster
SELECT lastName, firstName, salary
FROM main.employees
WHERE salary = 2000
OR salary = 2500

SQL.
, SQL
. SQL SELECT
.
.
SQL.

12.10.2011.

99

FLASH PLATFORM
SQL

SQL
SQL, ,
.

.
,
SQL. :

Run! ( SQL AIR, (Paul Robertson))


Lita ( SQLite, (David Deraedt))

12.10.2011.

100

101

9.

. Stats PerformanceTest,
Flash. Adobe Flash
Builder FlexPMD.

Stats

Stats, Flash mr.doob.
Stats : https://github.com/mrdoob/Hi-ReS-Stats.
Stats .

( , ).
( , ).
, . , ,
. .

, .
Stats .
import net.hires.debug.*;
addChild( new Stats() );

Adobe Flash Professional Flash Builder Stats.


CONFIG::DEBUG
{
import net.hires.debug.*;
addChild( new Stats() );
}

DEBUG, Stats.
, .

PerformanceTest
ActionScript (Grant Skinner) ,
.
PerformanceTest, . PerformanceTest
. PerformanceTest
http://www.gskinner.com/blog/archives/2009/04/as3_performance.html.

Flash Builder
Flash Builder , .

12.10.2011.

FLASH PLATFORM

. Flash Player,
.
, Adobe Flash Professional.
SWF- ActionScript Flex Flash Builder
. .
Flex Flash Builder 4.

FlexPMD
Adobe FlexPMD,
ActionScript 3.0. FlexPMD , JavaPMD, ActionScript.
FlexPMD ActionScript 3.0 Flex, .
,
, Flex.
FlexPMD Adobe,
http://opensource.adobe.com/wiki/display/flexpmd/FlexPMD. Eclipse
http://opensource.adobe.com/wiki/display/flexpmd/FlexPMD+Eclipse+plugin.
FlexPMD . FlexPMD
. .
,
, .

Flash Builder , .
SWF-.
SWF- , .
Flash Builder
.
. Flash Professional
. SWF- .

12.10.2011.

102