Posts tagged ‘Flash’

ActionScript based clock

a simple analog clock based on shapes.

download

all the ActionScript is all contained in a single file: Clock.as
this is added into the movie with #include “Clock.as” on the frame level

if there is interest, I’ll rewrite this as an object, add a few more options, and improve the script a bit.

it can be made small
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

or large
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

a Flash dice roller

a Flash dice roller using custom-rendered virtual dice.
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

of course, this could be customized to match a particular sort of roll and style of game.
the next version contains the ability to set all of the attributes from the HTML page, and to send the results back to it’s containing HTML page.

for example, in firewater productions’s game “Chaos University”, the standard is 5 dice:
(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

Flash loading progress animations

a simple image vewer, mostly put together to test transition effects and loading progress animation.
note: none of the viewers will ever load anything, the xml media list has only one dummy entry (to force it to continuously show the loading progress animation).

a shape based animation

an iconic clock, another shape based animation

a graphic based animation, this uses a single image, an offset, and a mask

a graphic based animation, this rotates a single image

A simple Flash game

a simple flash game thrown together quickly for the sole purpose of testing an ActionScript library.

Example of a Flash application passing data to the containing page

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque sollicitudin accumsan est. Sed volutpat elit ut diam. Mauris placerat placerat sem. Nullam non pede eget tellus adipiscing tempor. Duis ullamcorper. Cras sem justo, lacinia a, tempus vel, facilisis in, dui. Mauris eros erat, ultricies non, mattis nec, pulvinar at, libero. Proin purus. Donec interdum. Nam consequat dui. Ut nec leo. Nulla purus est, rutrum et, pretium ut, lacinia sollicitudin, felis. Nulla facilisi. Aliquam nibh eros, tempor vel, tincidunt eu, luctus id, metus. Praesent pellentesque.
This text is replaced by the Flash movie.

Flash Player and and a Javascript capable browser are requred.

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Quisque sollicitudin accumsan est. Sed volutpat elit ut diam. Mauris placerat placerat sem. Nullam non pede eget tellus adipiscing tempor. Duis ullamcorper. Cras sem justo, lacinia a, tempus vel, facilisis in, dui. Mauris eros erat, ultricies non, mattis nec, pulvinar at, libero. Proin purus. Donec interdum. Nam consequat dui. Ut nec leo. Nulla purus est, rutrum et, pretium ut, lacinia sollicitudin, felis. Nulla facilisi. Aliquam nibh eros, tempor vel, tincidunt eu, luctus id, metus. Praesent pellentesque.
This text is replaced by the Flash movie.

Flash Player and and a Javascript capable browser are requred.

Method to draw an ellipse

Notes:
as this method uses a series of lines to construct the curve, a low angular change will result in a smoother curve. however, if a higher value is used, this will construct what appear to be “warped” polygons. for example, an angular change of 45 degrees (Pi/4 rad) will give an eight sided polygon. changing the dx and dy will still result in an elliptical shape.

ActionScript:

with( MovieClip_Object ) {

	//center of ellipse
	var x0 = Stage.width/2;
	var y0 = Stage.height/2;
	//ellipse bounds
	var dx = 300;
	var dy = 100;
	//angular change
	var dn = 1 * (Math.PI/180);

	var r,x,y;
	lineStyle(1, 0x000000);
	for( var n=0; n<2*Math.PI; n+=dn ) {
		x = dx*Math.cos(n);
		y = dy*Math.sin(n);
		moveTo(x0+x,y0+y);
		x = dx*Math.cos(n+dn);
		y = dy*Math.sin(n+dn);
		lineTo(x0+x,y0+y);
	}

}

Bobble Head

A rather silly “bobble head” animation

in this version, the backend bases the force to apply on the number of clicks, it is also possible to base the force applied on the distance the head is dragged, or on length of time the head is clicked.

Simple Trig With ActionScript

angle conversion:

var angle_deg = angle_rad * 180/Math.PI;
var angle_rad = angle_deg * Math.PI/180;

find (x,y) from angle and radius:

var x = radius * cos( angle_rad );
var y = radius * sin( angle_rad );

a minor issue you will come across in ActionScript is that all of trigonometry functions in Math are based on the angle in radians, and a MovieClip’s _rotation property is based on the angle in degrees (this is not a bug or a flaw, but rather a design decision).

so a bit of simple algebra…

using a ratio:

angle_in_degrees/degrees_in_a_rotation = angle_in_radians/radians_in_a_rotation

one full rotation from origin to origin is 360 degrees or 2π radians:

plugged into the ratio:

angle_in_degrees/360 = angle_in_radians/2π

and solving for either variable:

angle_in_degrees/360 = angle_in_radians/2π

( angle_in_degrees/360 ) * 360 = ( angle_in_radians/2π ) * 360

angle_in_degrees = ( angle_in_radians * 360 ) /2π

angle_in_degrees = ( angle_in_radians * 180 ) /π

angle_in_degrees = angle_in_radians*180/π

and

angle_in_radians/2π = angle_in_degrees/360

( angle_in_radians/2π ) * 2π = ( angle_in_degrees/360 ) * 2π

angle_in_radians = ( angle_in_degrees/360 ) * 2π

angle_in_radians = ( angle_in_degrees/180 ) * π

angle_in_radians = angle_in_degrees*π/180

  • Tags

  • Categories

  • Need Code Written?

  • Need a Coding Job?

  • Archives