Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Colorize Function

/*
I don't use the flash colorize function much so this is an example of how to colorize a movieclip with a supplied hexnumber

colorize(0xff0000,my_movieClip);

//will turn my_movieClip bright red.
*/
function colorize(c:Number,mc:MovieClip){
  var tf:Transform = new Transform(mc);
  var color_tf:ColorTransform = new ColorTransform();
  color_tf.rgb = c;
  tf.colorTransform = color_tf;
};

actionscript drag and pan acorss a large image

This assumes the registration point is at the top left.

replace MY_MC with the name of a movieClip on your stage.

import mx.utils.Delegate;
grav = 0.82
img = MY_MC
mouseListener = new Object();
mouseListener.onMouseDown = Delegate.create(this,mouse_down);
mouseListener.onMouseMove = Delegate.create(this,e_point);
mouseListener.onMouseUp   = Delegate.create(this,mouse_up);
Mouse.addListener(mouseListener);


function s_point()
{
	sx_point = _xmouse;
	sy_point = _ymouse;
}

function mouse_down()
{
	pressed = true;
	s_point();
}

function mouse_up()
{
	pressed = false;
}

function e_point()
{
		if(pressed)
		{
			ex_point = _xmouse - sx_point
			ey_point = _ymouse - sy_point
		}
}

function onEnterFrame()
{
	ex_point*=grav;
	ey_point*=grav;
	
	img._x+=ex_point;
	img._y+=ey_point;
	
	if (Math.abs(img._x) > img._width - Stage.width) img._x = (img._width - Stage.width)*-1;
	if (Math.abs(img._y) > img._height - Stage.height) img._y = (img._height - Stage.height)*-1;
	if (img._x > 0) img._x = 0;
	if (img._y > 0) img._y = 0;
}
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS