[SIZE=3][COLOR=#000000][FONT=Arial]This code creates two zigzag lines that fall in a loop. I want to use bitmap data hittest with these lines, just to hit a simple object named “Touch1” at the bottom of the screen, but I do not know how. [/FONT][/COLOR]Does someone could write me the class because I’m new with AS3 and I’m a little lost.
[/SIZE][COLOR=#000000][FONT=Arial]
THANK YOU VERY MUCH FOR YOUR TIME
This is my code:
[/FONT][/COLOR][COLOR=#00008B]import[/COLOR] flash.display.[COLOR=#2B91AF]Graphics[/COLOR];
[COLOR=#00008B]import[/COLOR] flash.display.[COLOR=#2B91AF]MovieClip[/COLOR];
[COLOR=#00008B]import[/COLOR] flash.events.[COLOR=#2B91AF]Event[/COLOR];
[COLOR=#00008B]import[/COLOR] flash.events.[COLOR=#2B91AF]TimerEvent[/COLOR];
[COLOR=#00008B]import[/COLOR] flash.utils.[COLOR=#2B91AF]Timer[/COLOR];
[COLOR=#00008B]var[/COLOR] objectSpawner: [COLOR=#2B91AF]Timer[/COLOR];
[COLOR=#00008B]var[/COLOR] fallers: [COLOR=#2B91AF]Array[/COLOR];
[COLOR=#00008B]function[/COLOR] initGame(): [COLOR=#00008B]void[/COLOR] {
fallers = [];
objectSpawner = [COLOR=#00008B]new[/COLOR] [COLOR=#2B91AF]Timer/COLOR;
objectSpawner.addEventListener([COLOR=#2B91AF]TimerEvent[/COLOR].TIMER, createEnemy);
objectSpawner.start();
addEventListener([COLOR=#2B91AF]Event[/COLOR].ENTER_FRAME, dropEnemies);
}
[COLOR=#00008B]function[/COLOR] createEnemy(e: [COLOR=#2B91AF]TimerEvent[/COLOR]): [COLOR=#00008B]void[/COLOR] {
[COLOR=#00008B]var[/COLOR] enemy: [COLOR=#2B91AF]Faller[/COLOR] = [COLOR=#00008B]new[/COLOR] [COLOR=#2B91AF]Faller/COLOR;
enemy.y = -stage.stageHeight;
enemy.x = [COLOR=#2B91AF]Math[/COLOR].random() * [COLOR=#800000]380[/COLOR];
[COLOR=#2B91AF]MovieClip/COLOR.cacheAsBitmap = [COLOR=#00008B]true[/COLOR];
addChild(enemy);
fallers.push(enemy);
drawConnectors();
}
[COLOR=#00008B]function[/COLOR] dropEnemies(e: [COLOR=#2B91AF]Event[/COLOR]): [COLOR=#00008B]void[/COLOR] {
trace(fallers.length);
[COLOR=#00008B]for[/COLOR] each([COLOR=#00008B]var[/COLOR] mc: [COLOR=#2B91AF]Faller[/COLOR] [COLOR=#00008B]in[/COLOR] fallers) {
mc.y += [COLOR=#800000]10[/COLOR];
[COLOR=#00008B]if[/COLOR] (mc.y > stage.stageHeight * [COLOR=#800000]2[/COLOR]) fallers.splice(fallers.indexOf(removeChild(mc)), [COLOR=#800000]1[/COLOR]);
}
drawConnectors();
}
[COLOR=#00008B]function[/COLOR] drawConnectors(): [COLOR=#00008B]void[/COLOR] {
[COLOR=#00008B]if[/COLOR] (fallers.length == [COLOR=#800000]0[/COLOR]) [COLOR=#00008B]return[/COLOR];
[COLOR=#00008B]var[/COLOR] g: [COLOR=#2B91AF]Graphics[/COLOR] = [COLOR=#00008B]this[/COLOR].graphics;
g.clear();
g.lineStyle([COLOR=#800000]10[/COLOR],[COLOR=#800000]0xFFFFFF[/COLOR]);
[COLOR=#00008B]var[/COLOR] mc: [COLOR=#2B91AF]Faller[/COLOR] = fallers[[COLOR=#800000]0[/COLOR]];
g.moveTo(mc.x, mc.y);
[COLOR=#00008B]for[/COLOR] each(mc [COLOR=#00008B]in[/COLOR] fallers) g.lineTo(mc.x, mc.y);
}
init()
[COLOR=#00008B]function[/COLOR] init():[COLOR=#00008B]void[/COLOR]
{
[COLOR=#00008B]var[/COLOR] fallingThingsLeft:[COLOR=#2B91AF]FallingThings[/COLOR] = [COLOR=#00008B]new[/COLOR] [COLOR=#2B91AF]FallingThings[/COLOR](stage.stageWidth / [COLOR=#800000]2[/COLOR], stage.stageHeight);
[COLOR=#00008B]var[/COLOR] fallingThingsRight:[COLOR=#2B91AF]FallingThings[/COLOR] = [COLOR=#00008B]new[/COLOR] [COLOR=#2B91AF]FallingThings[/COLOR](stage.stageWidth / [COLOR=#800000]2[/COLOR], stage.stageHeight);
addChild(fallingThingsLeft);
addChild(fallingThingsRight);
fallingThingsRight.x = stage.stageWidth / [COLOR=#800000]2[/COLOR];
}
And this is the .as file named FallingThings
package
{
import flash.display.Graphics;
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.utils.Timer;
public class FallingThings extends Sprite
{
// set width
private var w:Number = 0;
// set height
private var h:Number = 0;
private var objectSpawner:Timer;
private var fallers:Array;
private var speed:Number = 10;
public function FallingThings(w:Number, h:Number)
{
this.w = w;
this.h = h;
init();
}
private function init():void
{
fallers = [];
objectSpawner = new Timer(1000);
objectSpawner.addEventListener(TimerEvent.TIMER, createEnemy);
objectSpawner.start();
addEventListener(Event.ENTER_FRAME, dropEnemies);
}
private function createEnemy(e:TimerEvent):void
{
var enemy:Faller = new Faller();
enemy.y = -h;
enemy.x = Math.random() * w;
MovieClip(enemy).cacheAsBitmap = true;
addChild(enemy);
fallers.push(enemy);
drawConnectors();
}
private function dropEnemies(e:Event):void
{
for each (var mc:Faller in fallers)
{
mc.y += speed;
if (mc.y > h * 2)
fallers.splice(fallers.indexOf(removeChild(mc)), 1);
}
drawConnectors();
}
private function drawConnectors():void
{
if (fallers.length == 0)
return;
var g:Graphics = this.graphics;
g.clear();
g.lineStyle(10,0xFFFFFF);
var mc:Faller = fallers[0];
g.moveTo(mc.x, mc.y);
for each (mc in fallers)
g.lineTo(mc.x, mc.y);
import flash.events.Event;
}
}
}