my code stock.com

Snippet options

Download: Download snippet as untitled.c.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

import flash.events.Event;

stage.frameRate = 50;  // para aumentar la velocidad de la pelicula

bola.x = 50; // posicion inicial
bola.y = 50;
e
var incrementoX:Number = 5; // variable de velocidad
var incrementoY:Number = 5;

stage.addEventListener(Event.ENTER_FRAME, mover);  // se ejecuta con cada fotograma

function mover(event:Event):void  //  funcion para mover la instancia bola
{
	bola.x += incrementoX; // incremmentos
	bola.y += incrementoY;
	
	// para el eje X	
	if (bola.x >= stage.stageWidth - (bola.width/2))
	{
		incrementoX *= -1;  // se multiplica por -1 para invertir la dirección
	}
	else
	if (bola.x <= 0 + (bola.width/2))
	{
		incrementoX *= -1;
	}
	
	// para el eje Y	
		if (bola.y >= stage.stageHeight - (bola.height/2))
	{
		incrementoY *= -1;
	}
	else
	if (bola.y <= 0 + (bola.height/2))
	{
		incrementoY *= -1;
	}
}

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.