setPixel (BitmapData.setPixel method)

public setPixel(x:Number, y:Number, color:Number) : Void

Sets the color of a single pixel of a BitmapData object. The current alpha channel value of the image pixel is preserved during this operation. The value of the RGB color parameter is treated as an unmultiplied color value.

Availability: ActionScript 1.0; Flash Player 8

Parameters

x:Number - The x position of the pixel whose value changes.

y:Number - The y position of the pixel whose value changes.

color:Number - The RGB color to which to set the pixel.

Example

The following example uses the setPixel() method to assign a RGB value to a pixel at a specific x and y position. You can draw on the created bitmap in 0x000000 by dragging.

import flash.display.BitmapData;

var myBitmapData:BitmapData = new BitmapData(100, 80, false, 0x00CCCCCC);

var mc:MovieClip = this.createEmptyMovieClip("mc", this.getNextHighestDepth());
mc.attachBitmap(myBitmapData, this.getNextHighestDepth());

mc.onPress = function() {
    this.onEnterFrame = sketch;
}

mc.onRelease = function() {
    delete this.onEnterFrame;
}

function sketch() {
    myBitmapData.setPixel(_xmouse, _ymouse, 0x000000);
}

See also

getPixel (BitmapData.getPixel method), setPixel32 (BitmapData.setPixel32 method)


Version 8

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/00001967.html