Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

Digital negative image with Actionscript 3.0

This is a discussion on Digital negative image with Actionscript 3.0 within the Tutorials forums, part of the Flash English category; You need to apply a digital negative effect on one or more images? This article will show you how to ...


Go Back   Forum Flash CS3 Flash CS4 > Flash CS3 Flash CS4 > Flash English > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  2 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 27-09-07, 13:07
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,535
Rep Power: 6
Flep is on a distinguished road
Digital negative image with Actionscript 3.0

You need to apply a digital negative effect on one or more images?
This article will show you how to do it using a digital negative matrix applied to the image with the ColorMatrixFilter class.
Applying to it an interval, we could play with it quite a lot...
In this example I apply 3 sliders to check the red, green and blue channels of the digital negative matrix.

Let's look at the example:

I create a FLA and save it as 'negativo.fla' in which,
I create 2 instances MovieClip named respectively 'img_mc' and 'pic_mc' inside which I insert an image.
I create 3 instances of the Slider component named respectively 'red_slider', 'green_slider', 'blue_slider'.
I create a Document Class, an AS file saved as 'Negativo.as', implemented the following way:
Code:
package
{
	import flash.display.MovieClip;
	import flash.filters.ColorMatrixFilter;
	import flash.events.Event;
	
	public class Negativo extends MovieClip
	{
		public function Negativo()
		{
			init();
			listener();
		}
		
		private function init():void
		{
			stage.frameRate=31;
			
			pic_mc.filters=[new ColorMatrixFilter(
			[-1,0,0,0,255,
			0,-1,0,0,255,
			0,0,-1,0,255,
			0,0,0,1,0])];
			
			red_slider.minimum=0;
			red_slider.maximum=255;
			red_slider.value=255;
			green_slider.minimum=0;
			green_slider.maximum=255;
			green_slider.value=255;
			blue_slider.minimum=0;
			blue_slider.maximum=255;
			blue_slider.value=255;
		}
		
		private function listener():void
		{
			pic_mc.addEventListener(Event.ENTER_FRAME,go);
			function go(e:Event):void
			{
				e.target.filters=[new ColorMatrixFilter(
				[-1,0,0,0,red_slider.value,
				0,-1,0,0,green_slider.value,
				0,0,-1,0,blue_slider.value,
				0,0,0,1,0])];
			}
		}
	}
}
The result:







Let's analise the code.

Methods


init();
I impost the frame rate
stage.frameRate=31;
I apply the negative matrix to 'pic_mc' using a new instance of the ColormatrixFilter class and assigning to it the filters property of the MovieClip (in fact 'pic_mc')
pic_mc.filters=[new ColorMatrixFilter(
[-1,0,0,0,255,
0,-1,0,0,255,
0,0,-1,0,255,
0,0,0,1,0])];
for each slider I assign a minimum and maximum value (minimum zero, maximum 255...the maximum value of the RGB scale) and also a starting value
red_slider.minimum=0;
red_slider.maximum=255;
red_slider.value=255;
green_slider.minimum=0;
green_slider.maximum=255;
green_slider.value=255;
blue_slider.minimum=0;
blue_slider.maximum=255;
blue_slider.value=255;

listener();
I add an interval ENTER_FRAME
pic_mc.addEventListener(Event.ENTER_FRAME,go);

go(e:Event):void
I apply the negative matrix based on the values obtained from the positions of the three sliders
e.target.filters=[new ColorMatrixFilter(
[-1,0,0,0,red_slider.value,
0,-1,0,0,green_slider.value,
0,0,-1,0,blue_slider.value,
0,0,0,1,0])];

Stay tuned !
__________________

 


I recommend: Essential Actionscript 3.0

- I do not reply technicians pvt messages. Open a thread !
- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Slicing an image with the Matrix Class of Actionscript 3.0 Flep Tutorials 7 17-11-08 01:48
Flash PHP guestbook + image lorenzz Flash CS3 | PHP | mySQL 1 12-11-08 18:12
slide image duca86 Flash CS3 Design 2 11-04-08 13:29
Resize image bulga Actionscript 3.0 base 8 10-03-08 06:39
Attach image from library with Flash CS3 and Actionscript 3.0 Flep Tutorials 0 09-10-07 19:14


All times are GMT. The time now is 17:36.

Powered by vBulletin version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap