Hi for all again, well today i was working with a loader class for a new project that use large images in background and these images can resized when resize browser or in different browser resolutions. When we load and add a large pictures into Flash it, when resized, distort the bitmap.

Well, reading and talking  about the bitmap class here in agency we discovery the smoothing propertie for Bitmap data and the most important is to make it true you dont need change big codes. Basically you need put a simple code on complete function of your loader class.

21
public function loadit(targetIt:String, smooth:Boolean = false):void

I put the smooth as Boolean to use it only when i need and only load pictures – not work with swf files. But to activate the smoothing you need on your complete function put this code like show:

44
45
46
47
48
if ( _smooth )
{
	var bmp:Bitmap = e.currentTarget.content;
	bmp.smoothing = true;
}

When e.currentTarget.content is equal the bitmap data that you loaded and after that you will put the bmp variable with smoothing equal true, aaaaaaaaaaand nothing more. So easy and great to work with large images into Flash. Lucky for all and cya.

APE – Actionscript Physics Engine – is an Actionscript 3 library that create physics objects into Flash, using Flash CS3 and CS4, with Flash Player 9, powerfull utility for Flash games because suport physics, collisions and others.

APE (Actionscript Physics Engine) is a free AS3 open source 2D physics engine for use in Flash and Flex, released under the MIT License. APE is written and maintained by Alec Cove.

A little sample of APE usage:

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

Use key A and D to move the car.

Well to begin the APE code we need download and import the class into your actionscript file. To download it you use SVN address: http://ape.googlecode.com/svn/ and to import into actionscript you need use these lines bellow:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package
{
	import flash.display.*;
	import org.cove.ape.*;
 
	public class apeSample extends MovieClip
	{
		private var apeGroup:Group;
		private var wheelr:WheelParticle;
		private var wheell:WheelParticle;
		private var wheelg:SpringConstraint;	
 
		public function apeSample():void
		{
			APEngine.init(1/4);
			APEngine.container = APEBox;
			APEngine.addForce(new VectorForce( false, 0, 2 ) );
			APEngine.damping = .98;
 
			apeGroup = new Group();
			apeGroup.collideInternal = true;
 
			APEngine.addGroup(apeGroup);
 
			APECar();
			APEState();
 
			addEventListener(Event.ENTER_FRAME, runAPE);
		}
 
		private function APECar():void
		{
			var rWheel:DisplayObject = new newBeatleWheel(); // For Custom Display
			wheelr = new WheelParticle(70,40,10,false,3);
			wheelr.setDisplay(rWheel);
			wheelr.addEventListener(CollisionEvent.COLLIDE, checkAPECollision);
 
			var lWheel:DisplayObject = new newBeatleWheel(); // For Custom Display
			wheell = new WheelParticle(144,40,10,false,3);
			wheell.setDisplay(lWheel);
 
			var carBox:DisplayObject = new carObject(); // For Custom Display
			wheelg = new SpringConstraint(wheelr,wheell,.5,true,2,1.6,true);
			wheelg.setDisplay(carBox,-1,15,180); 
 
			apeGroup.addParticle(wheelr);
			apeGroup.addParticle(wheell);
			apeGroup.addConstraint(wheelg);
		}
 
		private function APEState():void
		{
			var floor:RectangleParticle = new RectangleParticle(stage.stageWidth/2,stage.stageHeight/4,2000,20,0,true);
			apeGroup.addParticle(floor);
		}
 
		private function runAPE():void
		{
			APEngine.step();
			APEngine.paint();
		}
	}
}

A Simple sample of car running:

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

Use LEFT and RIGHT arrow to move the car.
Soon more codes and samples using APE Physics and bellow some links for download ando study it.

APE Site: http://www.cove.org/ape/
APE Google Group : http://groups.google.com/group/ape-general/

Flash Lite 3.1 includes the same features as Flash Lite 3.0, such as support for Flash Player compatible video, with some additional enhancements including improved security model for SWF file access. The solution delivers a standalone player for applications, without affecting the Flash Lite browser plug-in or pre-installed standalone player, if present.

Adobe Mobile Packager. The Adobe Mobile Packager is a desktop tool to wrap a SWF application with a player version checker, an icon, and metadata into an installable file for user-friendly discovery on S60 and Windows Mobile devices. The resulting output file is recognizable by S60 (.SIS) and Windows Mobile (.CAB) operating systems, acting essentially like .ZIP or .AIR files.

Authoring support is provided via Adobe Flash CS4 Professional and Adobe Device Central CS4 with corresponding updates, or via Adobe Flash CS3 Professional and Adobe Device Central CS3.

flashlite

1. Create
Create and test your Flash Lite application using Adobe Flash CS4 Professional and Adobe Device Central CS4 (with corresponding updates below), or Adobe Flash CS3 Professional and Adobe Device Central CS3.

2. Package
Use the Adobe Mobile Packager to wrap your SWF file with an icon, metadata, and a version checker that downloads the latest Flash Lite player over the air.

3. Distribute
Reach millions of users with direct-to-consumer distribution, or leverage the marketing reach and billing services of off-deck aggregator partners, including GetJar, Thumbplay, and Zed.

4. Discover
After downloading, your end users can discover your Flash application through a visual icon just like other applications on the device.

More info: http://labs.adobe.com/technologies/distributableplayer/

Video class in Actionscript 3

February 10th, 2009

Hi again for all, well think you creating a simple video player in max one minute.  ”Yes, We Can”.  Using  the videoPlayer class from asDataLibs. The videoPlayer is a simple way to make your video player or video gallery using less time than the normal process. Bellow some features:

• Support HD (h.264)
• Play and Pause button together;
• Mute button;
• Seek bar and loaded bar;
• Time played and total time of video.

In final of this post you will see the link to download the sample video player and the source code demonstrated in this article. See the sample of video Bellow.

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)
video by Flasher Magazine

Create the video is so simple like show these actionscript line ahead:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import com.dLibs.video.videoPlayer;
 
	public class main extends MovieClip
	{
		private var videoObject:videoPlayer;
		private var videoURL:String = "http://adobe.edgeboss.net/download/adobe/adobetv/flasher_magazine/issue_1/issue1.mp4";
		private var videoWidth:uint = 700;
		private var videoHeight:uint = 400;
		private var videoStart:Boolean = false;
 
		public function main():void
		{
			videoObject = new videoPlayer(videoURL,700,400,false);
			videoObject.addBuffer 		= newBuffer;
			videoObject.addPlayPause 	= playPause;
			videoObject.addMuteSound 	= muteIcon;
			videoObject.addDuration 	= seekControll.theTime;
			videoObject.addSeek 		= {progress:seekControll.seekProgress, loader:seekControll.seekLoader};
			newVideo.addChild(videoObject);
 
			// @ Change status of playPause Button
 
			playPause.addEventListener(MouseEvent.CLICK, changePlayPause);
		}
 
		private function changePlayPause(m:MouseEvent):void
		{
			if ( m.currentTarget.currentFrame == 1 ) 	{ m.currentTarget.nextFrame(); }
			else 										{ m.currentTarget.prevFrame(); }
		}
	}
}

In resume the videoPlayer object receive three variables:
• URL of video, width and height of video.
By default this video will play when buffer is full, but can change it sending ‘false’ withe the fourth variable that is if the video will start or not on load buffer complete. Other optional variable is buffer time. The complete object is:

new videoPlayer(videoURL:String,videoWidth:uint, videoHeight:uint, videoStart:Boolean = true, videoBuffer:uint = 10)

Now you can put the playpause button, mute button and seek too:

19
20
21
22
23
videoObject.addBuffer 		= newBuffer;
videoObject.addPlayPause 	= playPause;
videoObject.addMuteSound 	= muteIcon;
videoObject.addDuration 	= seekControll.theTime;
videoObject.addSeek 		= {progress:seekControll.seekProgress, loader:seekControll.seekLoader};

After that you need add this object in your stage and now see your video into Flash using Actionscript 3 easy.

Download the sample and source here.

Using Flex together Flash CS4

January 31st, 2009

Hi, now i will talk something about how work with Adobe Flex together with Adobe Flash CS4, and how it can speed your code and make increase your produtivity. Well, three simple things to change your coding to Flex is a complex project organizer into Flex, at the first time we load all the project and we can jump from the document classe for the import classe using a simple click in the import line. 

When we write the code, or beginner coders, can dont understant or dont know where is the ‘Event’ class. Using Flex when i write the code that use Event automaticly Flex create the import line into your class – Great. So, other thing is the ‘import help’, typing the import line the Flex make one list of classes that you found into com or gs or some class folder like show bellow:

import class

Of course for make this list we need put the our library folder using right click on your Project and select the Properties selection. Into Properties go to Actionscript Build Path and add a folder where have your classes or into Library Path can set your SWC file library.

Library folder

Other thing so much important to increase the produtivity is an Cold Fusion plugin update. You can see the install process in GotoAndLearn site in this tutorial. This update will install the Snip Tree View. Essencialy Snip make shortcuts to code functions, hmm great or no? Thing you type ef + CRTL or COMMAND + Space and appear in your code the lines:

addEventListener(Event.ENTER_FRAME, );

Well, it is totally possible using this new feature, see the preview bellow.

Snipet Tree View

These is some features that can make your job time better. Try use Flex Builder or install Flex plugin in your Eclipse and have a fun.

Using Google Maps API for Flash

January 30th, 2009

Hi for all again, well today i ll say something about the Google API for Flash Platform with Actionscript 3. I was looking for Google Maps class and in Lost in Actionscript have some classes for Google, Yahoo and Microsoft maps to make it but was in Google Maps API that i found a most simple way to create one Map into Flash using Actionscript 3. Simple like bellow:

import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.LatLng;
import com.google.maps.MapType;
 
var map:Map = new Map();
map.key = "YOUR_GOOGLE_MAP_KEY";
map.setSize(new Point(stage.stageWidth, stage.stageHeight));
map.addEventListener(MapEvent.MAP_READY, onMapReady);
addChild(map);
 
function onMapReady(event:Event):void {
  map.setCenter(new LatLng(-16.69395,-49.309988), 17, MapType.SATELLITE_MAP_TYPE);
}

You need create your App Key to use into your code:

map.key = "YOUR_GOOGLE_MAP_KEY";

Create your Key: http://code.google.com/apis/maps/signup.html and see the simple sample:

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

Map Flash SWC Library

dispatchEvent, i love you

January 28th, 2009

Yes, im loving so much the ‘dispatchEvent’. Understanding the why… I am working on Flash site using AMFPHP for one Hospital, into the site have some galleries that show medical team, the hospital and others. 

The Problem:
When i did the ‘for’ for create thumbs of the gallery i put the addEventListener(MouseEvent.CLICK, Function); but how run the first picture with out click it ? 

The Solution:
dispatchEvent of course ehehhe. Mr. dispatchEvent simulates the Event like the sample bellow:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var finalClip:Array = [clipOne,clipTwo,clip.....];
 
for ( var gi:uint = 0; gi < e.imagens.length; gi++ )
{
	var smLoader:Loader = new Loader();
	smLoader.load(new URLRequest(e.imagens[gi].thumbs));
 
	finalClip[gi].id = gi;
	finalClip[gi].mouseChildren = false;
	finalClip[gi].buttonMode = true;
	finalClip[gi].addChild(smLoader);
	finalClip[gi].addEventListener(MouseEvent.CLICK, showBigPicture);
}
 
finalClip[0].dispatchEvent(new MouseEvent(MouseEvent.CLICK));

The latest line of code sample do finalClip[0] (first clip of the array) execute the MouseEvent that you have calling showBigPicture function. So easy XD.
Enjoy it.

“There is a new ActionScript 3.0 API in Flash Player 10 to support RTMFP. Connecting to the Stratus service and creating end-to-end media streams are analogous to working with Flash Media Server. Please note that you must use ActionScript 3.0 with either Flash Professional CS4 or Flex Builder 3 targeting Flash Player 10 or AIR 1.5.”

Why use Stratus? hmm, well, Stratus is one sweet way to connect and trade data between users direct from Flash Player, eg. audio and video call or multi-player games. Like the AMFPHP, using Stratus you need first connect to service as show my code bellow:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package {
 
	import flash.display.*;
	import flash.events.*;
	import flash.net.*;
	import flash.media.*;
 
	public class stratusSample extends MovieClip
	{
 
		private const StratusAddress:String = "rtmfp://stratus.adobe.com";
		private const DeveloperKey:String = "YOUR_STRATUS_ID";
		private var netConnection:NetConnection;
		private var sendStream:NetStream;
		private var recvStream:NetStream;
 
		public function stratusSample():void
		{	
			netConnection = new NetConnection();
			netConnection.addEventListener(NetStatusEvent.NET_STATUS, netConnectionHandler);
			netConnection.connect(StratusAddress + "/" + DeveloperKey);
		}
 
		private function netConnectionHandler(e:NetStatusEvent):void
		{	
			trace("Net Status : " + e.info.code);
		}
	}
}

This will connect and show the status of connection, if was successfull or fail. To work you must use YOUR_STRATUS_ID that you will create in “labs.adobe.com/stratus”. I am working in one chat using Stratus and soon i ll publish source code here.  Any question comment. Thanks for all.

Create one simple gallery can take a time that you havent. Well, a simple solution that i create was gallLoader Class, one simple gallery that load thumbs, position thumbs in lines and load large image. Simple to use:

gallloaderpic

Have two arrows in right and left side of thumb container, these arrow will move container to view all other images using one more class named slideClip. Now you need only import and create these class objects like code bellow:

import com.dLibs.slider.slideClip;
import com.dLibs.photos.gallLoader;
 
var minData:Array = ["galeria/001/001.jpg", ...];
var maxData:Array = ["galeria/001/g001.jpg", ...];
 
var gallPict:gallLoader;
gallPict = new gallLoader(minData,maxData,gClip.bigImage,gClip.gImages,"gallThumb",4,2,gClip.LoadQuadAnim);
 
var galSlider:slideClip;
galSlider = new slideClip(gClip.gImages, gClip.gMask, gClip.gNext, gClip.gPrev);

Well, minData and maxData is an Array with thum and large images location.  We import slideClip and gallLoader classes, the first will make slider with container and other classe will create the gallery.

First create gallPict link and gallLoader object, and this new gallLoader object need receive in order: thumb array, large images array, MovieClip instance of large image, container instance, class of the thumb clip in library, padding or distance of thumb clips, number of lines that will separated thumbs and loader instance. Uffa ehehhe so many instances but the result is so many speedly.

Too need create slideClip object and set the clip instances: container clip instance, mask intance ( mask of container ), next and prev clip instance. Using click event will move and show all container clip with your thumbs. See the Flash simple gallery in action here:

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

Bellow the slideClip and gallLoader classes to view and save.

slideClip.as

package com.dLibs.slider
{
 
	import flash.display.*;
	import flash.events.*;
	import gs.TweenLite;
 
	public class slideClip
	{
 
		private var _contClip:MovieClip;
		private var _maskClip:MovieClip;
		private var _nextClip:MovieClip;
		private var _prevClip:MovieClip;
		private var _maxWidth:Number;
		private var _actWidth:Number;
 
		public function slideClip(contClip:MovieClip, maskClip:MovieClip, nextClip:MovieClip, prevClip:MovieClip)
		{
			/*
				To use this class
				var galSlider:slideClip = new slideClip(clip_Images, clip_Mask, clip_Next, clip_Prev);
				Clips that ll be slided, clip that mask the first, button to Next and to ultimate to Prev
			*/
 
			_contClip = contClip;
			_maskClip = maskClip;
			_nextClip = nextClip;
			_prevClip = prevClip;
 
			_nextClip.buttonMode = true;
			_prevClip.buttonMode = true;
 
			_maxWidth = _maskClip.width;
			_actWidth = _maskClip.x;
 
			slideInit();
		}
 
		private function verifyWidth():void
		{
			if ( _contClip.width <= _maxWidth ) _nextClip.visible = _prevClip.visible = false;
		}
 
		private function slideInit():void
		{
			_nextClip.addEventListener(MouseEvent.CLICK, showNext);
			_prevClip.addEventListener(MouseEvent.CLICK, showPrev);
 
			verifyWidth();
		}
 
		private function showNext(e:MouseEvent):void
		{
			if ( int(_actWidth) > int((_maskClip.x + _maxWidth ) - _contClip.width)  )
			{
				TweenLite.to(_contClip,.9, {x : _actWidth - _maxWidth});
				_actWidth = _actWidth - _maxWidth;
			}
		}
 
		private function showPrev(e:MouseEvent):void
		{
			if ( int(_actWidth) < int(_maskClip.x) )
			{
				TweenLite.to(_contClip,.9, {x : _actWidth + _maxWidth});
				_actWidth = _actWidth + _maxWidth;
			}
		}
	}
}

gallLoader.as

package com.dLibs.photos
{
 
	import flash.display.*;
	import flash.events.*;
	import flash.utils.*;
	import flash.net.*;
	import gs.TweenLite;
 
	public class gallLoader
	{
		/* @ Variables	 				____________________________________________________*/
 
		private var _minData		:Array;
		private var _maxData		:Array;
		private var _thmBox		:Array;
		private var _bigPict		:MovieClip;
		private var _smallPict		:MovieClip;
		private var _thmClip		:MovieClip;
		private var _thmMovie		:MovieClip;
		private var _bigMovie		:MovieClip;
		private var _loaderClip		:MovieClip;
		private var _thumbClass		:String;
		private var _loaderThumb	:Loader;
		private var _loaderBig		:Loader;
		private var _i			:uint;
		private var _thumbPadding	:uint;
		private var _thumbLines		:uint;
		private var _thumbLineY		:uint;
		private var _thumbLineX		:uint;
 
		/* @ Constructor 				____________________________________________________*/
 
		public function gallLoader(minData:Array,maxData:Array,bigPicture:MovieClip,smallPictures:MovieClip,thumbClass:String,thumbPadding:uint=0, thumbLines:uint=1,loaderClip:MovieClip=null):void
		{
			_minData 		= minData;
			_maxData 		= maxData;
			_bigPict 		= bigPicture;
			_smallPict 		= smallPictures;
			_thumbClass 	= thumbClass;
			_thumbPadding 	= thumbPadding;
			_thumbLines		= thumbLines;
			_loaderClip		= loaderClip;
 
			_thmBox = new Array();
 
			initGall();
		};
 
		/* @ init Function 				____________________________________________________*/
 
		private function initGall():void
		{
			if ( _loaderClip != null ) _loaderClip.visible = false;
 
			for ( _i = 0; _i < _minData.length; _i++ )
			{
				_loaderThumb 	= new Loader();
				_loaderThumb.x 	= _thumbPadding;
				_loaderThumb.y 	= _thumbPadding;
				_loaderThumb.load(new URLRequest(_minData[_i]));
				trace(_minData[_i] , _i);
 
				_thmClip 	= new ( getDefinitionByName(_thumbClass) as Class )();
				_thmClip.addChild(_loaderThumb);
 
				_thmMovie 		= new MovieClip();
				_thmMovie.x 	= ( _thmClip.width + 5 ) * _thumbLineX;
				_thmMovie.y		= ( _thmClip.height + 5 ) * _thumbLineY;
				_thmMovie.id 	= _i;
				_thmMovie.buttonMode = true;
				_thmMovie.addEventListener(MouseEvent.CLICK, viewPicture);
				_thmBox.push(_thmMovie);
				_thmMovie.addChild(_thmClip);
 
				_smallPict.addChild(_thmMovie);
 
				if ( _thumbLineY + 1 < _thumbLines )
				{
					_thumbLineY++;
				} else {
					_thumbLineY = 0;
					_thumbLineX++;
				}
			};
			_thmBox[0].dispatchEvent(new MouseEvent(MouseEvent.CLICK));
		};
 
		/* @ init Function 				____________________________________________________*/
 
		private function viewPicture(e:MouseEvent):void
		{
			_loaderBig = new Loader();
			_loaderBig.load(new URLRequest(_maxData[e.currentTarget.id]));
			_loaderBig.contentLoaderInfo.addEventListener(Event.COMPLETE, showLoadedBig);
			_loaderBig.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, showLoaderBig);
			trace(_maxData[e.currentTarget.id] , e.currentTarget.id);
 
			if ( _bigPict.numChildren > 1 ) _bigPict.removeChildAt(1);
		};
 
		private function showLoaderBig(e:ProgressEvent):void
		{
			if ( _loaderClip != null ) _loaderClip.visible = true;
		};
 
		private function showLoadedBig(e:Event):void
		{
			if ( _loaderClip != null ) _loaderClip.visible = false;
			_bigMovie 		= new MovieClip();
			_bigMovie.alpha = 0;
			_bigMovie.addChild(_loaderBig);
			_bigPict.addChild(_bigMovie);
 
			TweenLite.to(_bigMovie,.4,{ alpha : 1 });
		};
 
		/* @ End		 				____________________________________________________*/
 
	};
};

You can download the classes direct in repository: 
http://asdatalibs.googlecode.com/svn/trunk/

Any questions comment it. Thanks.
XD

AS3.0 Memory monitoring

December 2nd, 2008

Hi for all. Today i have some problems with a SWF file that stop all Flash Player Plug-in. First i thought that may be total memory used for the player, well, and now? What can i do to know total memory? Ta-daaaa. Reading the Flash Help – this page – i saw the propertie System.totalMemory.

Its so simple to use it, bellow the sample:

var memoryUsed:Number = (System.totalMemory / 1024 / 1024).toFixed(2));
trace(memoryUsed);

System.totalMemory give memory used in Bytes, to converte it to MegaBytes is necessary first convert to Kbyte (x/1024) and after that convert Kbyte to MByte (y/1024).

Use .toFixed() to especify how much numbers ll be appear after dot. (eg 10.45 or 105.23)
Any idea? Post your comment. Thanks and see you soon.