Hatena::Groupactionscript

ActionScript(AS3)やFlexを勉強しようと思ってはじめた日記

2009年03月25日 水曜日

はてなフォトライフの画像を表示してみる(7)

| 06:13 | はてなフォトライフの画像を表示してみる(7) - ActionScript(AS3)やFlexを勉強しようと思ってはじめた日記 を含むブックマーク はてなブックマーク - はてなフォトライフの画像を表示してみる(7) - ActionScript(AS3)やFlexを勉強しようと思ってはじめた日記 はてなフォトライフの画像を表示してみる(7) - ActionScript(AS3)やFlexを勉強しようと思ってはじめた日記 のブックマークコメント

一応、動きますが、やはり色々と不満が出てきています。ソースも全部貼ってみました。

問題

  • 1度読み込んだ画像は使い回したい
    • 何回も読み込みをしてしまう
    • サムネール画像を表示している間に、大きい画像を読み込んでおきたい
  • ちょっとした図形を用意するのが大変
    • たぶん馴れの問題なんだと思うけれど、三角形を右に45度回したいとか、一つ一つ調べる必要がある
  • 画面サイズの取得
    • stage.stageWidthとは...
    • サイズに関することにはぼんやりとした状態になりやすい
  • Alertのような全画面をぼんやりとさせる
    • filterがあるらしい
    • bitmapについて調整する機能があるらしい

サンプル画像

f:id:d4-1977:20090325061612p:image

fhatena.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:comp="*" layout="absolute" backgroundColor="0x000000">
	<comp:FhatenaViewer></comp:FhatenaViewer>
</mx:Application>

FhatenaViewer.as

package
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.*;
	import flash.net.*;
	import mx.core.UIComponent;
	import photo.Photo;
	import photo.PhotoInfomation;

	public class FhatenaViewer extends UIComponent
	{
		public var rdf:Namespace    = new Namespace("rdf",    "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
		public var dc:Namespace     = new Namespace("dc",     "http://purl.org/dc/elements/1.1/");
		public var hatena:Namespace = new Namespace("hatena", "http://www.hatena.ne.jp/info/xmlns#");
		public var canvas:Sprite    = new Sprite();

		public function FhatenaViewer()
		{
			createPhoto('http://f.hatena.ne.jp/d4-1977/rss');
		}

		public function createPhoto(feed:String):void
		{
			var loader:URLLoader = new URLLoader();
			loader.load(new URLRequest(feed));
			loader.addEventListener(Event.COMPLETE, createPhotoByXML);
			loader.addEventListener(ProgressEvent.PROGRESS, onLoading);
		}

		public function onLoading(event:ProgressEvent):void{}

		public function createPhotoByXML(event:Event):void
		{
			stage.stageFocusRect = false;
			var feed:XML = new XML(event.target.data);
			for each(var item:Object in feed.*::item){
				createPhotoItem(item.hatena::imageurlmedium,item);
			}
		}

		public function createPhotoItem(url:String,item:Object):void
		{
				var p:Photo = new Photo();
				p.property = item;
				p.x = (stage.width - p.width) * Math.random();
				p.y = (stage.height - p.height) * Math.random();
				addChild(p);
				p.loadImage(url);
				p.addEventListener(FocusEvent.FOCUS_IN,pFocusInHandler);
		}

		private function pFocusInHandler(event:FocusEvent):void
		{
			setChildIndex(event.currentTarget as DisplayObject, numChildren - 1);

			canvas.name = 'FhatenaViewer';
			addChild(canvas);
			setChildIndex(canvas, numChildren - 1);

			var p:PhotoInfomation = new PhotoInfomation();
			p.property = event.currentTarget.property;

			if(canvas.numChildren){
				canvas.removeChildAt(0);
			}

			canvas.addChild(p);
			p.loadImage(event.currentTarget.property.hatena::imageurl);
		}
	}
}

photo/Photo.as

package photo
{
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	
	public class Photo extends Sprite
	{
		public var property:Object;
		
		public function Photo()
		{
		}
		
		public function loadImage(url:String):void
		{
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadhandler);
			loader.load(new URLRequest(url));
		}

		public function loadhandler(event:Event):void
		{
			addChild(event.target.loader);
			rotation = Math.random() * 30 - 10;
			addEventListener(MouseEvent.MOUSE_DOWN,mouseDownHandler);
		}

		private function mouseDownHandler(event:MouseEvent):void
		{
			stage.focus = this;
		}
	}
}

photo/PhotoInfomation.as

package photo
{
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;
	import flash.text.*;
	
	public class PhotoInfomation extends Sprite
	{
		public var property:Object;
		public var photoImage:Sprite = new Sprite;
		public var infomationBox:Sprite = new Sprite;
		public var hatena:Namespace = new Namespace("hatena", "http://www.hatena.ne.jp/info/xmlns#");

		public function PhotoInfomation()
		{
		}

		public function loadImage(url:String):void
		{
			var loader:Loader = new Loader();
			loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loading);
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadhandler);    // 読み込み
			loader.load(new URLRequest(url));
		}

		public function loading(event:Event):void
		{
		}

		public function loadhandler(event:Event):void
		{
			// サイズ指定
			if((stage.stageWidth < event.target.loader.width) || (stage.stageHeight < event.target.loader.height)){
				var per:Number;
				var perW:Number = stage.stageWidth / event.target.loader.width;
				var perH:Number = stage.stageHeight / event.target.loader.height;
				if(perW > perH){
					per = perH;
				}else{
					per = perW;
				}
				event.target.loader.width  = int(event.target.loader.width * per) -20;
				event.target.loader.height = int(event.target.loader.height * per) - 20;
			}

			// 写真
			addChild(event.target.loader);
			setUpInfomation();
			addEventListener(MouseEvent.CLICK, clickListener);
			addEventListener(MouseEvent.MOUSE_OVER, mouseOverHandler);
			addEventListener(MouseEvent.MOUSE_OUT, mouseOutHandler);

			// 写真の位置
			this.x = int((stage.stageWidth - event.target.loader.width)/2);
			this.y = int((stage.stageHeight - event.target.loader.height)/2);
		}

		private function mouseOutHandler(event:Event):void
		{
			infomationBox.visible = false;			
		}

		private function mouseOverHandler(event:Event):void
		{
			infomationBox.visible = true;
		}

		private function setUpInfomation():void
		{
			// 文字列の場所
			infomationBox.graphics.beginFill(0x000000,0.5);
			infomationBox.graphics.drawRect(0, 0, this.parent.width, 50);
			infomationBox.graphics.endFill();
			// 文字列
			var text:TextField = new TextField();
			text.width     = this.parent.width;
			text.autoSize  = TextFieldAutoSize.RIGHT;
			text.htmlText  = '<font size="18" face="ヒラギノ角ゴ Pro W3"><b>' + property.*::title + '</b></font>';
			text.textColor = 0xffffff;
			infomationBox.addChild(text);
			//
			addChild(infomationBox);
			infomationBox.visible = false;
		}

		private function clickListener(event:Event):void
		{
			this.parent.removeChild(this);
		}
	}
}

CaioCaio2015/09/30 17:10something about the girl who had fallen from the roof... I got it! :DWell done! I hope to see fetuhrr updates on this. Maybe you can find some pictures for inside the cinema? That black color gave me the impression you couldn't see anything of the movie. :)Well done!

ArturoArturo2015/10/09 07:35Appreciate the kind comments. Have<a href="http://hfgzdxistr.com"> crutenrly</a> just submitted the sequel to the game company who is looking to publish it, so I suspect there will be updates in the next month or two.As for the pictures in the cinema... black is the color of imagination, eh? :-)

EesaEesa2015/10/09 11:59Hahaha! :DI'm really lniookg forward for the sequel (can't wait anymore, hehehe :) ). I can imagine that making a story like this is quite difficult and takes time. So I will have to wait, just as everyone else. Keep up the good work! http://sshroriwxmq.com [url=http://ewyekhvv.com]ewyekhvv[/url] [link=http://dwgrqvlj.com]dwgrqvlj[/link]

VloraVlora2015/10/10 06:42A perfect reply! Thanks for taking the <a href="http://qmvojs.com">trlueob.</a>

SamySamy2015/10/12 07:12Megali apogoiteusi o Kaklamanis .Isws h mreelutagi ever. Akoma ki o Abramopoulos kaluteros mou fainetai TOSO xalia ta exei paei o ..NikitasKi oxi mono gia thn x-mas periodo ,genikws. Osoi menoume se "kautes" perioxes ths a8inas (patissia ,kupseli, e3arxeia , pagrati kok) den exoume dei to paramikro na ginetai. Fwtismos xalia, skoupida pantou, pezodromia spasmena...Pou einai to prasino pou eta3e? Gia na mhn pw gia tis ...dwrean glastres meta tis fwties pou pote den dw8ikan. Den 8elw oute na ton akouw pia. Mas e3apatise oso kanenas dhmarxos. 8uammai tou ta exwne h Lifo alla molis phre dhmotiki diafhmisi stamatise ka8e kritiki.Wraioi dhmosiografoi ki autoi. Krima giati h A8ina mporei na einai polu pio omorfh. http://ugrbeyjtov.com [url=http://mbytwvdjwen.com]mbytwvdjwen[/url] [link=http://pluouiypq.com]pluouiypq[/link]