1、截获文本超链接事件
TextEvent.LINK
========================================================================
2、获取用户系统字体
trace(TextField.fontList);
========================================================================
3、改变可视化对象的颜色
var color:ColorTransform = sampleSprite.transform.colorTransform;
color.rgb = 0xFFFFFF;
sampleSprite.transform.colorTransform = color;
========================================================================
4、Matrix类(倾斜 缩放)
flash.geom.Matrix类定义了a,b,c,d,tx,和ty属性。b和c决定倾斜度(a和d决定缩放比,tx和ty
决定x和y平移值)。b属性决定Y坐标的倾斜值,c属性决定X坐标的倾斜值,b和c默认为0,值越
大越向下和向右倾斜。
默认值为(a=1, b=0, c=0, d=1, tx=0, ty=0)。
========================================================================
5、定时器
_timer = new Timer(30);
_timer.addEventListener("timer", onTimer);
_timer.start( );
========================================================================
6、查找一个字符串中是否包含一个指定的子串
String.indexOf(substr)
循环找出所有子串
while ( ( index = example.indexOf( "cool", index + 1 ) ) != -1 ) {
trace( "String contains word cool at index " + index );
}
========================================================================
7、join说明:将"<br>"替换为"\n",join( )方法重新加入新的分隔符
trace( example.split( "<br>" ).join( '\n' ) );
========================================================================
8、String的encode和decode
public static function encode( original:String ):String { // The codeMap property is assigned to the StringUtilities class when the encode( ) // method is first run. Therefore, if no codeMap is yet defined, it needs // to be created. if ( codeMap == null ) { // codeMap 属性是一个关联数组用于映射每个原始编码 codeMap = new Object( ); // 创建编码为0到255的数组 var originalMap:Array = new Array( ); for ( var i:int = 0; i < 256 ; i++ ) { originalMap.push( i ); } // 创建一个临时数组用于复制原始编码数组 var tempChars:Array = originalMap.concat( ); // 遍历所有原始编码字符 for ( var i:int = 0; i < originalMap.length; i++ ) { var randomIndex:int = Math.floor( Math.random( ) * ( tempChars.length - 1 ) ); codeMap[ originalMap[i] ] = tempChars[ randomIndex ]; tempChars.splice( randomIndex, 1 ); } } var characters:Array = original.split(""); for ( i = 0; i < characters.length; i++ ) { characters[i] = String.fromCharCode( codeMap[ characters[i].charCodeAt( 0 ) ] ); } } public static function decode( encoded:String ):String { var characters:Array = encoded.split( "" ); if ( reverseCodeMap == null ) { reverseCodeMap = new Object( ); for ( var key in codeMap ) { reverseCodesMap[ codeMap[key] ] = key; } } for ( var i:int = 0; i < characters.length; i++ ) { characters[i] = String.fromCharCode( reverseCodeMap[ characters[i].charCodeAt( 0 ) ] ); } return characters.join( "" ); } //调用 var example:String = "Peter Piper picked a peck of pickled peppers."; var encoded:String = StringUtilities.encode( example ); trace( StringUtilities.decode( encoded ) );
========================================================================
9、播放声音
//不缓冲
var _sound: Sound = new Sound(new URLRequest("1.mp3"));
_sound.play();
//缓冲 5秒
var request:URLRequest = new URLRequest("1.mp3");
var buffer:SoundLoaderContext = new SoundLoaderContext(5000);
_sound = new Sound( );
_sound.load(request, buffer);
_sound.play( );
//循环播放,第一个参数为起始播放位置
_sound.play(0, int.MAX_VALUE);
========================================================================
10、声音载入进度条
package { import flash.display.Sprite; import flash.media.Sound; import flash.net.URLRequest; import flash.events.Event; public class ProgressBar extends Sprite { public function ProgressBar( ) { addEventListener(Event.ENTER_FRAME, onEnterFrame); _sound = new Sound(new URLRequest("song.mp3")); _sound.play( ); } public function onEnterFrame(event:Event):void { var barWidth:int = 200; var barHeight:int = 5; var loaded:int = _sound.bytesLoaded; var total:int = _sound.bytesTotal; if(total > 0) { // Draw a background bar graphics.clear( ); graphics.beginFill(0xFFFFFF); graphics.drawRect(10, 10, barWidth, barHeight); graphics.endFill( ); // The percent of the sound that has loaded var percent:Number = loaded / total; // Draw a bar that represents the percent of // the sound that has loaded graphics.beginFill(0xCCCCCC); graphics.drawRect(10, 10, barWidth * percent, barHeight); graphics.endFill( ); } } } }
========================================================================
11、声间的播放/暂停
package { import flash.display.Sprite; import flash.media.Sound; import flash.media.SoundChannel; import flash.net.URLRequest; import flash.events.Event; import flash.display.Sprite; import flash.events.MouseEvent; public class PlayPause extends Sprite { private var _sound:Sound; private var _channel:SoundChannel; private var _playPauseButton:Sprite; private var _playing:Boolean = false; private var _position:int; public function PlayPause( ) { // Create sound and start it _sound = new Sound(new URLRequest("song.mp3")); _channel = _sound.play( ); _playing = true; // A sprite to use as a Play/Pause button _playPauseButton = new Sprite( ); addChild(_playPauseButton); _playPauseButton.x = 10; _playPauseButton.y = 20; _playPauseButton.graphics.beginFill(0xcccccc); _playPauseButton.graphics.drawRect(0, 0, 20, 20); _playPauseButton.addEventListener(MouseEvent.MOUSE_UP, onPlayPause); } public function onPlayPause(event:MouseEvent):void { // If playing, stop. Take note of position if(_playing) { _position = _channel.position; _channel.stop( ); } else { // If not playing, re-start it at // last known position _channel = _sound.play(_position); } _playing = !_playing; } } }