PDA

View Full Version : TV Static [as3]



rai_kane3
November 11th, 2008, 12:02 PM
Here is senoculars TV Static converted to AS3

original as2 link (http://www.senocular.com/flash/source.php?id=0.200)




import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;

// create a new movie clip for the static
var static_mc:MovieClip = new MovieClip();

this.addChild(static_mc);

// position the static movie clip with the mask
static_mc.x = mask_mc.x;
static_mc.y = mask_mc.y;

// create a bitmap data instance the size of the mask
// that will be used to draw static in
var _bitmapData = new BitmapData(mask_mc.width, mask_mc.height);
var _bitmap = new Bitmap(_bitmapData)

// attach the bitmap to the static movie clip
static_mc.addChild(_bitmap);

// apply the mask
static_mc.mask = mask_mc;

static_mc.addEventListener(Event.ENTER_FRAME, _static);

// every frame draw static
function _static(e:Event):void
{
var seed:int = int(Math.random() * int.MAX_VALUE);
_bitmapData.noise(seed, 0, 0xFFFFFF, BitmapDataChannel.RED, true);
}

da457nilo
December 26th, 2008, 09:01 PM
I tried using this static file but couldn't figure out how to put anything on top of it. Any ideas?

rai_kane3
December 30th, 2008, 10:10 PM
could you give me a little more about what your wanting to do?

at a guess you could place the code inside a mc, and create a new layer above and add what you want on that layer but thats a guess.

da457nilo
January 2nd, 2009, 05:55 PM
Ya that worked thanks!

rai_kane3
January 2nd, 2009, 08:26 PM
no problem

FlashPlaya
January 21st, 2009, 11:51 PM
Hey rai_kane3

Is there any way to make the boxes any bigger? Thanks!

dmitriysorokin
January 27th, 2009, 08:09 PM
I tried using this static file but couldn't figure out how to put anything on top of it. Any ideas?
I have the same problem.

rai_kane3
January 29th, 2009, 01:15 PM
Hey rai_kane3

Is there any way to make the boxes any bigger? Thanks!

The static size is based on the size of the mask, increase the mask and the static should fill the mask area


so e.g

mask_mc.width = 300;
mask_mc.height = 200;

as for adding something ontop of the static if you read the previous post you can place this code inside a movieclip on the stage and place your content on a new layer above.

alternativly if you wanted to code it instead try this.

create a new movieClip in the library and give is a class name of Content.

please any text images or anything else you want in here.

to increase the static size just set the maskers graphic.draw to a what ever with or size you want




import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.BitmapDataChannel;

// create a new movie clip for the static

var static_mc:MovieClip = new MovieClip();
var container:MovieClip = new MovieClip();
var _content:Content = new Content();
var masker:Sprite = new Sprite();
var padding:Number = 10;

masker.graphics.beginFill(0x0000FF);
// set the width of the mask
masker.graphics.drawRect(0,0,250,100);
masker.graphics.endFill();

addChild(container);
addChild(_content);

container.addChild(masker);
container.addChild(static_mc);

// Container is placed in the center
container.x = stage.stageWidth / 2 - container.width / 2;
container.y = stage.stageHeight / 2 - container.height / 2;

// content matches container position with padding
_content.x = container.x + padding;
_content.y = container.y + padding;

// position the static movie clip with the mask
static_mc.x = masker.x;
static_mc.y = masker.y;

// create a bitmap data instance the size of the mask
// that will be used to draw static in
var _bitmapData = new BitmapData(masker.width, masker.height);
var _bitmap = new Bitmap(_bitmapData)

// attach the bitmap to the static movie clip
static_mc.addChild(_bitmap);

// apply the mask
static_mc.mask = masker;

static_mc.addEventListener(Event.ENTER_FRAME, _static);

// every frame draw static
function _static(e:Event):void
{
var seed:int = int(Math.random() * int.MAX_VALUE);
_bitmapData.noise(seed, 0, 0xFFFFFF, BitmapDataChannel.RED, true);
}

kyinaire
June 26th, 2010, 05:11 PM
I'm completely new to AS3.0 and partly new to Flash itself, so could someone please describe in detail how to add a shape (say a circle) on top of static? I don't particularly care about the TV. I tried all your methods in various combinations in CS4 Professional but they don't seem to work.

Any help would be greatly appreciated.

mmlitved
January 13th, 2012, 07:13 AM
agbpetpe

snickelfritz
January 13th, 2012, 11:39 AM
// draw red circle with 100 pixel radius
var circle:Shape = new Shape();
var g:Graphics = circle.graphics;
g.beginFill(0xFF0000, 1);
g.drawCircle(0,0,100);
g.endFill();

// place circle at center of stage
circle.x = stage.stageWidth/2;
circle.y = stage.stageHeight/2;

// add circle after adding the other content
addChild(container);
addChild(content);
addChild(circle);