Other Websites

  • SeaCloud9 Interactive
  • SeaCloud9 Commercial Development
  • i-os
  • stArcade9

Brendon Smith Social Networks

  • On Linkedin
  • Bookmarks
  • On Twitter
  • On Facebook
Open ↓ Close ↑
  • Home
  • Subscribe
Browse: Home / ActionScript, Flash, i-create / Tweet Tank in Away3D and Hype pt. 2
i-create | therefore-i am
i-create | therefore i-am | a blog about opensource technology and rich internet applications
 

Tweet Tank in Away3D and Hype pt. 2

By Brendon Smith on May 16, 2010

 

I have now added support to search twitter. Once you search twitter it repopulates the fish bowl with fish that once clicked will navigate to that twitter search result. I have been working on optimizing the content. Specifically the fish models are very processor intensive. I have been looking at different ways to improve this. Away3Dlite is new than the other versions and it does have many benefits. The main build has other techniques like level of detail and fogging. These help to reduce the over all processor hit. I believe in the near future some of these features will hopefully be ported over to the Away3Dlite version if not then within in the next couple of weeks I will port this over. I think utilizing fogging and level of detail will greatly reduce the overall processor hit.

Processor Intensive Experiment:

You will notice that when it renders it is rendering 110+ DisplayObject3D I have also been working on Garbage Collection I have found that after doing several searches the Memory is increasing greatly. So I have added some techniques like removing the objects and then nullifying them although it doesn’t appear to be helping much. I will have to look into this again soon. I would also like to super impose a Google map on the top make it click-able and then have the camera zoom in on that particular fish which should not really be difficult at all because I can use tween lite to simply zoom the camera to the objects position. So I am not done with this and I will be revisiting these issues. Memory management can be difficult. I will also be scouring the web for flash tools that help profile and reduce memory so if anyone has any suggestions feel free to chime in. I have also been reading the 3D in Flash Book from Friends of Ed it does have a whole chapter on optimizing 3D content for the web so I will be reading that chapter soon. I have also been looking at gSkinners blog it has a considerable amount in regards to memory management.
The Source Code:

package {
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.display.MovieClip;
	import flash.media.Sound;
	import flash.media.SoundChannel;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.system.System;
 
	public class TweetTank extends Sprite {
		public var twitterFish:tweetFish;
		public var searchClipGo:searchClip = new searchClip();
		public var sound:Sound;
		private var musicChannel;
		public function TweetTank() {
			addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler, false, 0, true);
		}
 
		private function addedToStageHandler(e:Event):void {
			playMusic();
			twitterFish=new tweetFish;
			addChild(twitterFish);
			twitterFish._twitSearch = "Flash";
			twitterFish.init();
			twitterFish.visible = true;
			addChild(searchClipGo);
			searchClipGo.x = 250;
			searchClipGo.y = 30;
			searchClipGo.btnSearch.addEventListener(MouseEvent.CLICK, TweetSearch);
			removeEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
		}
 
		public function TweetSearch(e:MouseEvent):void{
			//trace(searchClipGo.txtSearch.text);
			try{
			this.twitterFish.killAll();
			this.twitterFish.xMove = null;
			this.twitterFish.twFishOne = null;
			this.twitterFish = null;
			twitterFish=new tweetFish;
			addChild(twitterFish);
			twitterFish._twitSearch  = searchClipGo.txtSearch.text;
			twitterFish.init();
 
			twitterFish.visible = true;
 
			addChild(searchClipGo);
			searchClipGo.x = 250;
			searchClipGo.y = 30;
			searchClipGo.btnSearch.addEventListener(MouseEvent.CLICK, TweetSearch);
			System.gc();
			// the GC will perform a full mark/sweep on the second call.
			}catch(fail:Error){
				//trace(fail);
			}
		}
 
 
		public function playMusic():void {
			sound = new Sound();
			sound.load( new URLRequest( "test.mp3" ) );
			musicChannel=sound.play(0, int.MAX_VALUE);
			try{
 
			}catch(e:Error){
				musicChannel.removeEventListener(Event.SOUND_COMPLETE, loopMusic);
			}
			musicChannel.addEventListener(Event.SOUND_COMPLETE, loopMusic);
		}
 
		public function loopMusic(e:Event):void {
			if (musicChannel!=null) {
 
				playMusic();
			}
		}
 
	}
}
 
 
package {
	import away3dlite.containers.ObjectContainer3D;
	import away3dlite.materials.*;
	import away3dlite.materials.WireColorMaterial;
	import away3dlite.primitives.Cube6;
	import away3dlite.templates.BasicTemplate;
	import away3dlite.core.base.*;
	import away3dlite.core.utils.*;
	import away3dlite.events.*;
	import twFish.*;
	import twTank.*;
	import RSSJSONW;
	import com.theflashblog.utils.Math2;
 
	import com.adobe.utils.XMLUtil;
	import com.adobe.serialization.json.JSON;
	import com.adobe.xml.syndication.rss.Item20;
	import com.adobe.xml.syndication.rss.RSS20;
	import flash.events.IOErrorEvent;
	import flash.events.EventDispatcher;
	import flash.events.SecurityErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.net.URLRequestMethod;
	import flash.system.Security;
 
	import flash.events.KeyboardEvent;
	import flash.ui.Keyboard;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Vector3D;
	import flash.media.Sound;
	import flash.display.*;
	import flash.net.URLRequest;
	import flash.display.Bitmap;
	import flash.display.BlendMode;
	import flash.filters.BlurFilter;
	import flash.filters.GlowFilter;
	import flash.media.SoundChannel;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	import flash.system.System;
 
	import gs.TweenLite;
 
	import hype.extended.behavior.FunctionTracker;
	import hype.extended.layout.GridLayout;
	import hype.framework.sound.SoundAnalyzer;
 
 
	public class tweetFish extends BasicTemplate {
		private var origin:Vector3D=new Vector3D(0,40,900);
		public var twFishOne:TwFish1;
		public var twTankC:TwTank1;
		public var soundAnalyzer:SoundAnalyzer;
		private var myX:Number=0;
		public var layout:GridLayout;
		public var Tank:ObjectContainer3D;
		public var xMove:FunctionTracker;
		public var _twitSearch:String;
		public var xScaleTracker:FunctionTracker;
		public var yScaleTracker:FunctionTracker;
		public var zScaleTracker:FunctionTracker;
		[Bindable]public var myRSS:RSSJSONW;
		Security.loadPolicyFile("http://twitter.com/crossdomain.xml");
		Security.allowInsecureDomain("*");
		Security.allowDomain("*");
		public var myTimer:Timer = new Timer(1000);
		public var colourScheme:Array=[0x18b849,0x1858b8,0x18b81c,0x18b89c,0xb818b2,0xfd02f4,0x3102fd,0x02b3fd,0x1afd02,0xf4fd02,0xfd02f4,0x3102fd,0x02b3fd,0x1afd02,0xf4fd02];
		public function tweetFish() {
			super();
		}
 
		public function init():void {
			stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheelEvent, false, 0, true);
			var filterA:Array=new Array  ;
			filterA.push(new GlowFilter(0xFFFFFF, 1, 19, 19, 1, 1, false, false));
			var blur:BlurFilter = new BlurFilter();
			blur.blurX=900;
			blur.blurY=900;
			filterA.push(blur);
			soundAnalyzer = new SoundAnalyzer();
			soundAnalyzer.start();
			layout=new GridLayout(-900,-175,30,30,60);
			Tank = new ObjectContainer3D();
			view.scene.addChild(Tank);
			Tank.addEventListener(MouseEvent3D.MOUSE_MOVE, goFish,false, 0, true);
			twTankC=new TwTank1(view);
			view.scene.addChild(twTankC);
			view.mouseEnabled=true;
			jsonInit("http://search.twitter.com/search.json?q=" + _twitSearch);
			camera.z=-2000;
			camera.x=-1600;
			camera.y=400;
			camera.lookAt( origin );
			stage.addEventListener(MouseEvent.CLICK,_checkMouseEventTrail,false,0,true);
			stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDown, false, 0, true);
 
		}
 
		public function jsonInit(siteFeed:String):void
			{
				myRSS = new RSSJSONW();;
				myRSS._data = "";
				myRSS._txtURL = siteFeed;
				myRSS.onJSON(myRSS._txtURL);
				myTimer.start();
				myTimer.addEventListener("timer", timedFunction);
			}
			public function timedFunction(eventArgs:TimerEvent):void
			{
				if (myRSS._IsReady == "true")
				{
					myTimer.stop();	
					addFish(myRSS);
				}
			}
		//Really Helpful for tracing events!	
		public function _checkMouseEventTrail($e:MouseEvent):void {
			var p:* =$e.target;
			while (p) {
 
				//trace(">>", p.name,": ",p);
				p=p.parent;
			}
		}
 
		public function killAll():void {
			xMove.stop();
			xScaleTracker.stop();
			yScaleTracker.stop();
			zScaleTracker.stop();
			xScaleTracker = null;
			yScaleTracker = null;
			zScaleTracker = null;
			view.scene.removeChild(twFishOne);
			view.scene.removeChild(twTankC);
			xMove = null;
			twTankC = null;
			twFishOne = null;
			System.gc();
			trace("Killed");
		}
 
		public function addFish(myRSS:RSSJSONW):void{
			//trace(myRSS._twdata.length);
			var numFish:Number;
			if(myRSS._twdata.length >= 6){
				numFish = 6;
			}else{
				numFish = myRSS._twdata.length;
			}
			for (var i:uint = 0; i<numFish; i++) {
				//trace(view);
				twFishOne=new TwFish1(view);
				if (i!=0) {
					twFishOne.x=i*randRange(-200,400);
					twFishOne.y=i*randRange(-200,400);
					twFishOne.z=i*randRange(-200,400);
				}
				var baseFrequency:uint = (90 % 64)*4;
				xMove=new FunctionTracker(twFishOne,"scale",dancingFish,[i,twFishOne]);
				xMove.start();
				//trace(twFishOne.x);
				//var fishy:Object3D=twFishOne;
				//twFishOne.clipContainer.addChild(twFishOne);
				//twFishOne.addChild(twFishOne);
				view.scene.addChild(twFishOne);
 
				twFishOne.name=i.toString();
 
				//fishy.layer.blendMode = BlendMode.ADD;
				twFishOne.addEventListener(MouseEvent3D.MOUSE_DOWN, goFish,false, 0, true);
				System.gc();
 
			}
		}
		protected function goFish(event:MouseEvent3D):void {
			//trace(myRSS._twdata[int(event.currentTarget.name)]);		
			var myURL:URLRequest = new URLRequest(myRSS._twdata[int(event.currentTarget.name)]);
			navigateToURL(myURL);
		}
		public function onMouseWheelEvent(event:MouseEvent):void {
			//trace(event.delta);
			TweenLite.to(camera,1,{z: event.delta * 500 + camera.z,onUpdate: onCameraMove});
		}
		private function keyDown(e:KeyboardEvent):void {
			//trace(e);
			switch (e.keyCode) {
				case 32 :
					moveCamera();
					break;
			}
		}
 
		public function randRange(min:Number, max:Number):Number {
			// Generate a number between and including min - max
			var randomNum:Number = Math.floor(Math.random()*(max-min+1))+min;
			return randomNum;
		}
 
		private function dancingFish(i:uint, twFishOne:TwFish1):void {
			var baseFrequency:uint = (i % 64)*4;
			//trace(baseFrequency + "-Beat");
			xScaleTracker=new FunctionTracker(twFishOne,"scaleX",soundAnalyzer.getFrequencyRange,[baseFrequency,baseFrequency+4,1,2]);
			yScaleTracker=new FunctionTracker(twFishOne,"scaleY",soundAnalyzer.getFrequencyRange,[baseFrequency,baseFrequency+4,1,2]);
			zScaleTracker=new FunctionTracker(twFishOne,"scaleZ",soundAnalyzer.getFrequencyRange,[baseFrequency,baseFrequency+4,1,2]);
			TweenLite.to(twFishOne, 5, {x:twFishOne.x + 50, y:twFishOne.y + 50, z:twFishOne.z + 50});
			xScaleTracker.start();
			yScaleTracker.start();
			zScaleTracker.start();
		}
		private function moveCamera():void {
			//trace("In Move Camera");
			TweenLite.to(
			                    camera, 
			                    4, 
			                    {
			                        x: Math2.rand(-9000, 9000),
			                        y: Math2.rand(-9000, 9000),
			                        z: 1400 + Math2.rand(-9800, 9000),
			                        delay: 2,
			                        onUpdate: onCameraMove
			                    }
			                );
 
		}
 
		private function onCameraMove():void {
			camera.lookAt( origin );
		}
 
 
		override protected function onPreRender():void {
			Tank.rotationY++;
 
		}
	}
}

Download Code / Launch Experiment

I also like what I have been seeing in the WebGL community. I think it would be really cool if haXe created a library for exporting to webGL/JavaScript I think this would have many benefits namely I could use my Away3D skills and export to webGL. They do currently export to Canvas but at this time I am not aware of any WebGL support within haXe. HaXe does support openGL for use in its vitual machine Neko so it seems that a library will likely be available soon.

  • Share/Bookmark

Related posts:

  1. Tweet Tank in Away3D and Hype
  2. Away3D with Hype Fish Tank
  3. Virtual Painting with Hype
  4. Simple Flip3D in ActionScript3
  5. Yahoo Pipes RSS & JSON ActionScript Revisited

Posted in ActionScript, Flash, i-create | Tagged 3d, ActionScript, as3, Away3D, data visualization, Experiment, hype, interactive, twitter

Brendon Smith

GUI Development, Action Script, Java Script, .NET, AJAX, Java, PHP, CakePHP, Mashup Development, Flash, Silverlight, C#, XML, SQL, Apache, IIS, Photoshop, Fireworks,etc.. Oh, and Biking and Camping

  • Ped mbor
    Hi
    I relay like the 3D object in the top right corner which shoes the different text as a button link for different pages. How I can make something similar to that. I know 3D modelling, flash and I’m beginner to away3D.
    Could you please help me?
    Thanks
    Pedro
  • seacloud9
    Structure Synth to create those images. I experimented with algorithms to generate the images. I rendered the images with sunflower. The rendering can be tricky so here is the rendering script I used to export to Sunflow. Structure Synth is truly an interesting tool for creating unique images.
    <template "$file.png""="" $file"-o="" defaultextension="Sunflow scene file (*.sc)" name="Sunflow" runafter="%SUNFLOW%\sunflow.bat "><description> Modified Basic Template: </description><primitive name="begin"></primitive><primitive name="end"></primitive><primitive name="box"></primitive><primitive name="sphere"></primitive></template>
    I also recommend reading a few books:

    Algorithmic Architecture
    Algorithms for Visual Design Using the Processing Language

    Flash and Generative Art:Keith Peters on Flash
    Also look at the Hype Framework
blog comments powered by Disqus
« Previous Next »
 
 

3d ActionScript Adobe Air Android Apollo Apple art as3 Away3D C# CakePHP CSS Experiment Flash Flash Develop Flex Games Generative Design Google HTML5 hype JavaScript Joshua Davis JQuery JSON Life Linux MashUp OpenSource Open Source PaperVision3D PC History Processing quick tip RIA Silverlight Technology/Internet travel twitter Web webGL Webware XML Yahoo Pipes

WP Cumulus Flash tag cloud by Roy Tanck and Luke Morton requires Flash Player 9 or better.

  • Monthly
  • Yearly
  • Links
  • August 2010
  • June 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • 2010
  • 2009
  • 2008
  • 2007
  • 2006
  • 2005
  • agit8
  • Away3D
  • Ben Nadel
  • Bit-101
  • Bruce Jawn
  • Causecast
  • D.I.Y.
  • Dr Woohoo
  • draw.logic
  • Flight404
  • Flong
  • generatorX
  • gSkinner
  • haXe
  • Jonathan Snook
  • Joshua Davis
  • Jot
  • Kirupa
  • LifeHacker
  • Make
  • Minor White
  • Mr Doob
  • NihiLogic
  • NurseOnTheRun
  • octane42
  • OpenFrameWorks
  • Processing
  • PV3D
  • Senocular
  • Sephiroth
  • ShineDraw
  • Stroep
  • SWX
  • Tech News
  • Toxi
  • UnitZeroOne
  • World We Live In
  • ZeusLabs

Photos

Hamburg_panoramic.jpg

Recent Comments

  • seacloud9 on Tweet Tank in Away3D and Hype pt. 2
  • Brendon Smith on Tweet Tank in Away3D and Hype pt. 2

RSS LifeStream

  • Elysium
  • Giles Bowkett: Archaeopteryx: A Ruby MIDI Generator
  • Grant Nestor » Blog Archive » Generative music, huh?

Copyright © 2010 i-create | therefore-i am.