电子邮件:flashindream[AT]gmail[DOT]com
略懂Flash的天文爱好者
将基于AVM1Movie的SWF编码成AS3的MovieClip类
Post by indream, 2010-6-18, Views:/*
* ForcibleLoader
*
* Licensed under the MIT License
*
* Copyright (c) 2007-2009 BeInteractive! (www.be-interactive.org) and
* Spark project (www.libspark.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
package
{
import flash.display.Loader;
import flash.net.URLRequest;
import flash.net.URLStream;
import flash.events.IOErrorEvent;
import flash.events.SecurityErrorEvent;
import flash.events.Event;
import flash.utils.ByteArray;
import flash.utils.Endian;
import flash.errors.EOFError;
/**
* Loads a SWF file as version 9 format forcibly even if version is under 9.
*
* Usage:
* <pre>
* var loader:Loader = Loader(addChild(new Loader()));
* var fLoader:ForcibleLoader = new ForcibleLoader(loader);
* fLoader.load(new URLRequest('swf7.swf'));
* </pre>
*
* @author yossy:beinteractive
* @see http://www.be-interactive.org/?itemid=250
* @see http://fladdict.net/blog/2007/05/avm2avm1swf.html
*/
public class ForcibleLoader
{
public function ForcibleLoader(loader:Loader)
{
this.loader = loader;
_stream = new URLStream();
_stream.addEventListener(Event.COMPLETE, completeHandler);
_stream.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
_stream.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
}
private var _loader:Loader;
private var _stream:URLStream;
public function get loader():Loader
{
return _loader;
}
public function set loader(value:Loader):void
{
_loader = value;
}
public function load(request:URLRequest):void
{
_stream.load(request);
}
private function completeHandler(event:Event):void
{
var inputBytes:ByteArray = new ByteArray();
_stream.readBytes(inputBytes);
_stream.close();
inputBytes.endian = Endian.LITTLE_ENDIAN;
if (isCompressed(inputBytes)) {
uncompress(inputBytes);
}
var version:uint = uint(inputBytes[3]);
if (version < 9) {
updateVersion(inputBytes, 9);
}
if (version > 7) {
flagSWF9Bit(inputBytes);
}
else {
insertFileAttributesTag(inputBytes);
}
loader.loadBytes(inputBytes);
}
private function isCompressed(bytes:ByteArray):Boolean
{
return bytes[0] == 0x43;
}
private function uncompress(bytes:ByteArray):void
{
var cBytes:ByteArray = new ByteArray();
cBytes.writeBytes(bytes, 8);
bytes.length = 8;
bytes.position = 8;
cBytes.uncompress();
bytes.writeBytes(cBytes);
bytes[0] = 0x46;
cBytes.length = 0;
}
private function getBodyPosition(bytes:ByteArray):uint
{
var result:uint = 0;
result += 3; // FWS/CWS
result += 1; // version(byte)
result += 4; // length(32bit-uint)
var rectNBits:uint = bytes[result] >>> 3;
result += (5 + rectNBits * 4) / 8; // stage(rect)
result += 2;
result += 1; // frameRate(byte)
result += 2; // totalFrames(16bit-uint)
return result;
}
private function findFileAttributesPosition(offset:uint, bytes:ByteArray):uint
{
bytes.position = offset;
try {
for (;;) {
var byte:uint = bytes.readShort();
var tag:uint = byte >>> 6;
if (tag == 69) {
return bytes.position - 2;
}
var length:uint = byte & 0x3f;
if (length == 0x3f) {
length = bytes.readInt();
}
bytes.position += length;
}
}
catch (e:EOFError) {
}
return NaN;
}
private function flagSWF9Bit(bytes:ByteArray):void
{
var pos:uint = findFileAttributesPosition(getBodyPosition(bytes), bytes);
if (!isNaN(pos)) {
bytes[pos + 2] |= 0x08;
}
}
private function insertFileAttributesTag(bytes:ByteArray):void
{
var pos:uint = getBodyPosition(bytes);
var afterBytes:ByteArray = new ByteArray();
afterBytes.writeBytes(bytes, pos);
bytes.length = pos;
bytes.position = pos;
bytes.writeByte(0x44);
bytes.writeByte(0x11);
bytes.writeByte(0x08);
bytes.writeByte(0x00);
bytes.writeByte(0x00);
bytes.writeByte(0x00);
bytes.writeBytes(afterBytes);
afterBytes.length = 0;
}
private function updateVersion(bytes:ByteArray, version:uint):void
{
bytes[3] = version;
}
private function ioErrorHandler(event:IOErrorEvent):void
{
loader.contentLoaderInfo.dispatchEvent(event.clone());
}
private function securityErrorHandler(event:SecurityErrorEvent):void
{
loader.contentLoaderInfo.dispatchEvent(event.clone());
}
}
}
汉字转拼音_AS3
Post by indream, 2010-5-23, Views:Char2Pinyin类:
点击 Char2Pinyin.zip 下载
结点引力球效果_AS3
Post by indream, 2010-5-21, Views:import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Point;
import com.FPS;
addChild(new FPS());
var dotNum:Number = 40;
var list:Array = []
for(var i=0;i<dotNum;i++){
var ball:MovieClip = new MovieClip();
with(ball.graphics){
beginFill(0xffcc00,0.9);
drawCircle(0,0,3);
endFill();
}
if(i==0){
ball.mass = 20
ball.x = stage.stageWidth*0.5;
ball.y = stage.stageHeight*0.5;
}else{
ball.mass = Math.random()+1;
ball.speedX = 0;
ball.speedY = 0;
ball.x = stage.stageWidth/2+Math.random()*300-150;
ball.y = stage.stageHeight/2+Math.random()*300-150;
}
addChild(ball);
list.push(ball)
}
this.addEventListener(Event.ENTER_FRAME,loop);
function loop(evt):void{
this.graphics.clear();
for(var i=0;i<list.length;i++){
if(i!=0){
list[i].speedX*=0.999;
list[i].speedY*=0.999;
list[i].x += list[i].speedX;
list[i].y += list[i].speedY;
}
}
for(i=0;i<list.length;i++){
for(var j=i;j<list.length;j++){
if(i!=j){
var dis:Number = dist(new Point(list[i].x,list[i].y),new Point(list[j].x,list[j].y));
if(dis>4){
var mass = (list[i].mass+list[j].mass);
var _power_out:Number = 0.5*mass;
var _power_in:Number = 25*mass;
var _power = -_power_out/Math.pow(dis,2)+_power_in/Math.pow(dis,3);
if(i!=0){
list[i].speedX += _power*(list[i].x-list[j].x);
list[i].speedY += _power*(list[i].y-list[j].y);
}
list[j].speedX -= _power*(list[i].x-list[j].x);
list[j].speedY -= _power*(list[i].y-list[j].y);
}
}
}
}
}
function dist(pt0:Point,pt1:Point):Number{
var dx = pt0.x - pt1.x;
var dy = pt0.y - pt1.y
var dis = Math.sqrt(dx*dx+dy*dy);
if(dis<40){
this.graphics.lineStyle(0.5,0x00ccff,Math.max(0,1-dis/40));
this.graphics.moveTo(pt0.x,pt0.y);
this.graphics.lineTo(pt1.x,pt1.y);
}
return dis;
}
程序员的骄傲: 我用AS3写出了房子,车子,老婆及未来.
Post by indream, 2010-5-6, Views:trace("房子,车子,老婆,未来");
Tags: as3
Hot Articles
Friend Connect
New Articles
Archives
- 2010 August (5)
- 2010 June (7)
- 2010 May (10)
- 2010 April (2)
- 2010 March (4)
- 2010 February (3)
- 2010 January (3)
- 2009 December (2)
- 2009 November (7)
- 2009 October (8)
- 2009 September (6)
- 2009 August (11)
- 2009 July (9)
- 2009 June (2)
- 2009 May (9)
- 2009 April (8)
- 2009 March (6)
- 2009 January (2)
- 2008 December (6)
- 2008 November (4)
- 2008 October (1)
- 2008 August (3)
- 2008 July (2)
- 2008 June (9)
- 2008 May (8)
- 2008 April (20)
- 2008 March (4)
- 2008 January (1)
- 2007 December (3)
- 2007 November (7)
- 2007 October (6)
- 2007 September (1)
- 2007 August (10)
- 2007 July (11)
- 2007 June (5)
- 2007 April (4)
- 2007 March (10)
- 2007 February (4)
- 2007 January (10)
- 2006 December (17)
- 2006 November (11)
- 2006 October (6)
- 2006 September (19)
- 2006 August (22)
Favorite
Links
Statistics
- 文章总数:312
- 评论总数:194
- 引用总数:0
- 浏览总数:1747
- 留言总数:1
- 当前主题:sean
- 当前样式:Sean_Sim
