In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: prototype shogi.

将棋の駒を透過pngで作成し、Loaderを使用し、ロードし、
Bitmap.bitmapdate.clone()を使い、スプライトに描写しています。
 しかし、透過pngであるはずの駒が透過されません。
 どのような方法で読み込めば画像が透過されるでしょうか?
URLの末尾のmが原因です。
Get Adobe Flash player
by paq 10 Jun 2010

    Talk

    applicott at 10 Jun 2010 19:10
    そういうことだったんですか! 分かりました、ありがとうございます。

    Tags

    Embed
/**
 * Copyright paq ( http://wonderfl.net/user/paq )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/vj0c
 */

// forked from applicott's prototype shogi.
package
{
	
	// 将棋の駒を透過pngで作成し、Loaderを使用し、ロードし、
	//  Bitmap.bitmapdate.clone()を使い、スプライトに描写しています。
	//  しかし、透過pngであるはずの駒が透過されません。
	// どのような方法で読み込めば画像が透過されるでしょうか?
	
	// URLの末尾のmが原因です。
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;
	import flash.text.TextFormat;
	
	[SWF(width="665", height="665", frameRate="30", backgroundColor="0x000000")]
	public class Main extends Sprite {		
	private var HIRATE:Array=[
		[2,3,4,5,7,5,4,3,2],
		[0,9,0,0,0,0,0,8,0],
		[1,1,1,1,1,1,1,1,1],
		[0,0,0,0,0,0,0,0,0],
		[0,0,0,0,0,0,0,0,0],
		[0,0,0,0,0,0,0,0,0],
		[1,1,1,1,1,1,1,1,1],
		[0,8,0,0,0,0,0,9,0],
		[2,3,4,5,6,5,4,3,2],
	];
//		private const KomaList:Array =[
//			new Komaimg("http://hot.main.jp/flex/img/koma_nasi.png","なし",0),
//			new Komaimg("http://hot.main.jp/flex/img/koma_fu.png","歩兵",1),
//			new Komaimg("http://hot.main.jp/flex/img/koma_kyosha.png","香車",2),
//			new Komaimg("http://hot.main.jp/flex/img/koma_keima.png","桂馬",3),
//			new Komaimg("http://hot.main.jp/flex/img/koma_ginsho.png","銀将",4),
//			new Komaimg("http://hot.main.jp/flex/img/koma_kinsho.png","金将",5),
//			new Komaimg("http://hot.main.jp/flex/img/koma_ousho.png","王将",6),
//			new Komaimg("http://hot.main.jp/flex/img/koma_gyoku.png","玉将",7),
//			new Komaimg("http://hot.main.jp/flex/img/koma_kaku.png","角行",8),
//			new Komaimg("http://hot.main.jp/flex/img/koma_hisya.png","飛車",9),
//			new Komaimg("http://hot.main.jp/flex/img/koma_ryuou.png","竜王",10),
//			new Komaimg("http://hot.main.jp/flex/img/koma_ryuma.png","龍馬",11),
//			new Komaimg("http://hot.main.jp/flex/img/koma_tokin.png","と",12),
//			new Komaimg("http://hot.main.jp/flex/img/koma_narikin.png","全",13),
//			new Komaimg("http://hot.main.jp/flex/img/ban.png","盤",100),
//		];
		
		private const KomaList:Array =[
			new Komaimg("http://assets.wonderfl.net/images/related_images/4/44/448c/448c2a3f4517557143fffaf8c441faa8b5843004","なし",0),
			new Komaimg("http://assets.wonderfl.net/images/related_images/9/9a/9a60/9a604dd2840a0cb072139dadf910724479132661","歩兵",1),
			new Komaimg("http://assets.wonderfl.net/images/related_images/2/2d/2d3c/2d3cb9af7698f4b45d89548094ace18eeea1b14d","香車",2),
			new Komaimg("http://assets.wonderfl.net/images/related_images/6/6b/6bbe/6bbe4511914dd907413678aea1ac8040d1595093","桂馬",3),
			new Komaimg("http://assets.wonderfl.net/images/related_images/9/96/96e2/96e2b34f957ba1fdcd8cd16580a2522a661074a5","銀将",4),
			new Komaimg("http://assets.wonderfl.net/images/related_images/1/12/129d/129d0639f61e6abcba63ad7b8403deca852ac051","金将",5),
			new Komaimg("http://assets.wonderfl.net/images/related_images/5/56/5698/56984fdbb15baef952d8bd0119be622c6c99d819","王将",6),
			new Komaimg("http://assets.wonderfl.net/images/related_images/f/fa/fa77/fa7743e1e81b16bc8f9bacd8f2fbfef6d9ba485f","玉将",7),
			new Komaimg("http://assets.wonderfl.net/images/related_images/e/e9/e9d9/e9d9032759e1229b7ede86201445b1b72cb8454c","角行",8),
			new Komaimg("http://assets.wonderfl.net/images/related_images/2/27/27d2/27d286fd588bde1ec0b471bac468d2a1c4c05238","飛車",9),
			new Komaimg("http://assets.wonderfl.net/images/related_images/6/6d/6d7f/6d7fc59b823843b995f9ba2a9f86177b0ae3c997","竜王",10),
			new Komaimg("http://assets.wonderfl.net/images/related_images/d/db/dbef/dbefc3d31abe51ee15101a0f09cb0171a972cece","龍馬",11),
			new Komaimg("http://assets.wonderfl.net/images/related_images/f/f6/f63e/f63e2188eb6d99d155e4b17a8b3a49168f6e41bc","と",12),
			new Komaimg("http://assets.wonderfl.net/images/related_images/5/53/53c4/53c4b24db4ce82e73dcf2ca58ebe5386f0fa5dcc","全",13),
			new Komaimg("http://assets.wonderfl.net/images/related_images/a/a2/a282/a282f1c436d11822620cc5796a2497a8a0829772","盤",100),
		];
		private var loaded:int = 0;		//読み込み完了した画像の個数
		private const NUM:uint = 14;
		
		private var map:Sprite;
		private const SCALE:Number = 1; //倍率
		
		private const MAPSIZE:uint = 9;//マップの横・縦のマスの個数
		private const FLDSIZEX:uint = 47;
		private const FLDSIZEY:uint = 57;//フィールド(マップ上の1マス)の横・縦のドット数
		// load画像格納用
		private var img:Array = [];
		private var offsetX:uint = 16;
		private var offsetY:uint = 16;
		
		private var komaA:Array = [];
		
		public function Main(){
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
			

			
			//テキストフォーマット設定
			var format:TextFormat=new TextFormat();
			format.color=0x000000
			format.size=13;
			format.font='_等幅';
			format.leading = 10;
			format.align = "center"
			format.bold=true;
			
			//使う画像を読み込んでおく
			map = new Sprite();	
			loadIMG();
			addChild(map);
			
			
			//表示ボタン設定
			var bt:Button = new Button('手前ランダム配置',150)
			bt.x = stage.stageWidth-200;
			bt.y = stage.stageHeight-300;
			bt.addEventListener(MouseEvent.CLICK, rundom);
			addChild(bt);
			var bt2:Button = new Button('全面ランダム配置',150)
			bt2.x = stage.stageWidth-200;
			bt2.y = stage.stageHeight-200;
			bt2.addEventListener(MouseEvent.CLICK, Zenrundom);
			addChild(bt2);
			//
			var bt3:Button = new Button('敵ランダム配置',150)
			bt3.x = stage.stageWidth-200;
			bt3.y = 50;
			bt3.addEventListener(MouseEvent.CLICK, rundom2);
			addChild(bt3);
			
		}
		
		
		private function rundom(e:MouseEvent):void{
			
//			for(var i:uint = 6; i < 80; i+=9){
//				var c:int = Math.floor(Math.random() * 3)+i;
//				var kx:int=	komaA[i].image.x;
//				var ky:int=	komaA[i].image.y;
//				komaA[i].image.x = komaA[c].image.x;
//				komaA[i].image.y = komaA[c].image.y;
//				komaA[c].image.x = kx;
//				komaA[c].image.y = ky;	
//			}
			for(var i:uint = 7; i < MAPSIZE; i++){
				for(var j:uint = 7; j < MAPSIZE; j++){
					
					
					var c:int = Math.floor(Math.random() * 2+1)+6 + Math.floor(Math.random() * 9)*9;
					if (i*MAPSIZE+j == c) continue;
					var kx:int=	komaA[i*MAPSIZE+j].image.x;
					var ky:int=	komaA[i*MAPSIZE+j].image.y;
					komaA[i*MAPSIZE+j].image.x = komaA[c].image.x;
					komaA[i*MAPSIZE+j].image.y = komaA[c].image.y;
					komaA[c].image.x = kx;
					komaA[c].image.y = ky;
					
				}
			}
			
			
		}		
		private function rundom2(e:MouseEvent):void{
			
			
			for(var i:uint = 0; i < MAPSIZE; i++){
				for(var j:uint = 0; j < 3; j++){
					
					
					var c:int = Math.floor(Math.random() * 3);
					if (i*MAPSIZE+j == c) continue;
					var kx:int=	komaA[i*MAPSIZE+j].image.x;
					var ky:int=	komaA[i*MAPSIZE+j].image.y;
					komaA[i*MAPSIZE+j].image.x = komaA[c].image.x;
					komaA[i*MAPSIZE+j].image.y = komaA[c].image.y;
					komaA[c].image.x = kx;
					komaA[c].image.y = ky;
					
				}
			}
			
			
		}
		
		private function Zenrundom(e:MouseEvent):void{
			
			
			for(var i:uint = 0; i < MAPSIZE; i++){
				for(var j:uint = 0; j < MAPSIZE; j++){
					var c:int = Math.floor(Math.random() * (i*MAPSIZE+j + 1));
					if (i*MAPSIZE+j == c) continue;
					var kx:int=	komaA[i*MAPSIZE+j].image.x;
					var ky:int=	komaA[i*MAPSIZE+j].image.y;
					komaA[i*MAPSIZE+j].image.x = komaA[c].image.x;
					komaA[i*MAPSIZE+j].image.y = komaA[c].image.y;
					komaA[c].image.x = kx;
					komaA[c].image.y = ky;
				
				}
			}
			
					
		}
				
		
		//各画像のロード
		private function loadIMG():void {
			var loader:Loader = new Loader();
			var koma:Komaimg = KomaList[14];
			
			//盤のロード
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void{loaded++;}); //ロード完了したらloadedをカウントアップ
			loader.load(new URLRequest(koma.url), new LoaderContext(true));
			map.addChild(loader);
			
			//各こまのロード
			for (var i:uint = 0; i < NUM; i++) {
				loader = new Loader();
				koma = KomaList[i];
				if(i==NUM-1){
					loader.contentLoaderInfo.addEventListener(Event.COMPLETE,Create); 
				}else{
					loader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event):void{loaded++;}); //ロード完了したらloadedをカウントアップ
					
				}
				loader.width= FLDSIZEX;
				loader.height= FLDSIZEY;
				loader.load(new URLRequest(koma.url), new LoaderContext(true));
				img.push(loader);
			}
		}
		private function Init(e:Event=null):void{
			//駒の生成 と 初期配置
			for(var i:uint = 0; i < MAPSIZE; i++){
				for(var j:uint = 0; j < MAPSIZE; j++){
					var enemy:Boolean;
					(j<3)? enemy=true : enemy=false;
					
					var image:B2Sprite = new B2Sprite(img[0].content);					
					var k:Koma = new Koma(image,i,j,1,enemy,false);
					komaA.push(k);
					komaA[i*MAPSIZE+j].image.x = FLDSIZEX * i+offsetX;
					komaA[i*MAPSIZE+j].image.y = FLDSIZEY * j+offsetY;
					addChild(komaA[i*MAPSIZE+j]);
					
				}
				
			}
		}
		private function Create(e:Event=null):void{
			//駒の生成 と 初期配置
			for(var i:uint = 0; i < MAPSIZE; i++){
				for(var j:uint = 0; j < MAPSIZE; j++){
					var enemy:Boolean;
					(j<3)? enemy=true : enemy=false;
					
					var image:B2Sprite = new B2Sprite(img[HIRATE[j][i]].content);					
					var k:Koma = new Koma(image,i,j,HIRATE[i][j],enemy,false);
					komaA.push(k);
					komaA[i*MAPSIZE+j].image.x = FLDSIZEX * i+offsetX;
					komaA[i*MAPSIZE+j].image.y = FLDSIZEY * j+offsetY;
				komaA[i*MAPSIZE+j]..width= FLDSIZEX;
				komaA[i*MAPSIZE+j]..height= FLDSIZEY;
					addChild(komaA[i*MAPSIZE+j]);
					
				}
				
			}
		}
		
	}
	
	
		
}



class B2Sprite extends Sprite
{
	public function B2Sprite(image:Bitmap):void
	{
		if(image!=null){
		var img:Bitmap = new Bitmap(image.bitmapData.clone());
		addChild(img);}
	}
}




import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;

class Komaimg {
	public var url:String;			
	public var name:String;
	public var num:uint;
	public var image:Loader;
	public function Komaimg(_url:String,s:String="", _num:uint =1):void {
		url = _url;
		name = s;
		num=_num;
	}
}

class Koma extends Sprite {
	public const FLDSIZEX:uint = 47;
	public const FLDSIZEY:uint = 57;//フィールド(マップ上の1マス)の横・縦のドット数
	public var url:String;			//画像のURL
	public var names:String;
	public var num:uint;
	public var image:B2Sprite;
	public var i:uint; //座標
	public var j:uint;
	public var enemy:Boolean;
	public var komanum:uint;
	public var naru:Boolean;
	public var joutai:Number=0;
	public var Xzure:Number=4;
	public function Koma(im:B2Sprite,_i:uint,_j:uint,komanum:uint,enemy:Boolean=false,naru:Boolean=false):void {
		image = im;
		i=_i;
		j=_j;
		addChild(image);
		if(enemy) enemyRotate();
	}
	
	private function enemyRotate():void{
		image.rotation=180;
		x+=FLDSIZEX-6;
		y+=FLDSIZEY-2;
	}
}


class Fu extends Koma {
	public function Fu(im:B2Sprite,_i:uint,_j:uint,komanum:uint,enemy:Boolean=false,naru:Boolean=false):void {
		super(im,_i,_j,1);
		
		image.addEventListener(MouseEvent.CLICK,onclick);
	}
	public function onclick(e:MouseEvent):void{
		//e.target.y-=FLDSIZEY;
		var sen:Sprite = new Sprite();
		sen.graphics.beginFill(0x2288aa);
		sen.graphics.drawRect(0,0,FLDSIZEX,FLDSIZEY);
		sen.graphics.endFill();
		sen.alpha=0.1;
		sen.x=e.target.x-Xzure;
		sen.y=e.target.y-FLDSIZEY;
		
		
		addChild(sen);
		
	}
}




import flash.display.*;
import flash.text.*;
class Button extends SimpleButton
{
	
	public function Button(label:String, width:int = 0):void
	{
		var up:Sprite = _buildImage(label, 0xCCCCCC, width);
		var over:Sprite = _buildImage(label, 0xFFCCCC, width);
		var down:Sprite = _buildImage(label, 0xCC9999, width);
		down.y = 1;
		super(up, over, down, up);
	}
	
	private static function _buildImage(label:String, color:int, width:int = 0):Sprite
	{
		var text:TextField = new TextField();
		text.defaultTextFormat = new TextFormat('Verdana', 10, 0x000000, true, null, null, null, null, TextFormatAlign.CENTER);
		text.autoSize = TextFieldAutoSize.CENTER;
		text.selectable = false;
		text.text = label;
		text.x = (width - text.width) >> 1;
		text.y = 5;
		var base:Shape = new Shape();
		var g:Graphics = base.graphics;
		g.beginFill(color);
		g.drawRect(0, 0, width, text.height + 10);
		g.endFill();
		var sp:Sprite = new Sprite();
		sp.addChild(base);
		sp.addChild(text);
		return sp;
	}
}