Menu:

Sponsor

Place your advertising here
casininio casino online casino online Buy and sell flash files

 

Forum's topics

Latest Files

Archives

Top Rated

Categories

Photo Gallery


BitmapData.threshold howto

Description

"Tests pixel values in an image against a given threshold and set pixels that pass the test to new color values. Using the threshold() method you can isolate and replace color ranges in an image and perform other logical operations on image pixels"
threshold has been introduced in Flash Player 8

1. Basic Example

As first let's take a simple example in order to better understand the way threshold work

and this is the code used:

import flash.display.BitmapData
import flash.geom.Point
import flash.geom.Rectangle

var img1:BitmapData = BitmapData.loadBitmap("img2")
var img2:BitmapData = new BitmapData(img1.width, img1.height, false)
var mc:MovieClip = this.createEmptyMovieClip("holder", 1)
mc.attachBitmap(img1, 1)
mc.attachBitmap(img2, 2)
var myList:Object = new Object();
myList.change = function(target:MovieClip){
img2.threshold(img1, new Rectangle(0, 0, img1.width, img1.height), new Point(0, 0), ">=", (target.value/100)*0xFFFFFF, 0xFFFF00, 0xffffff, true);
}
slider.addEventListener("change", myList)
myList.change(slider)

 

this is the way the threshold method work:
public threshold(sourceBitmap:BitmapData, sourceRect:Rectangle, destPoint:Point, operation:String, threshold:Number, color:Number, mask:Number, copySource:Boolean) : Number

We have to focus on the threshold argument:
The value that each pixel will be tested against to see if it meets or exceeds the threshhold.

 

2. Advanced Example

Now, let's create an image viewer making transitions use the threshold method.

Set up the folders in this way:

  • the "files" folder will contain your .fla file and your "index.xml" files.
  • "img" folder will contain all the images described in the xml file
  • "classes/it/sephiroth" contains the "Fader.as" class file

 

First thing let's create an xml file like this, which contains all the path of the images we want to load in the image viewer (just remember to put all these images in a "img" folder):

<?xml version='1.0' encoding='UTF-8'?>
<images>
<image path='img/img10.jpg'/>
<image path='img/img1.jpg'/>
<image path='img/img4.jpg'/>
<image path='img/img3.jpg'/>
<image path='img/img2.jpg'/>
<image path='img/img5.jpg'/>
<image path='img/img6.jpg'/>
<image path='img/img7.jpg'/>
<image path='img/img8.jpg'/>
<image path='img/img9.jpg'/>
</images>

Create a new Flash document with a movieclip inside called "image".
Add this code to the first frame of the main timeline:

import it.sephiroth.Fader
var xmlFile:String = "index.xml"
var ifader:Fader = new Fader(xmlFile, image)

 

Under the publish settings remember to add the "classes" folder to the actionscript classes related to this file.

At this point we just need to setup the "Fader" class actionscript file.