[Flashcoders] Help with code

2011-02-12 Thread Renata
English is not my native language, so I apologize if you make mistakes of 
agreement or spellings.
AS3 study and made this game for three year olds who can notmove with mouse, to 
run it, there is an error and I can not makeit back to the home page.

Below the code and the error message.
I do not know whether you are permitted to place the filesattached so I 
reproduce the code below.

package  
{
//importar classes
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.utils.Timer;
import flash.utils.getDefinitionByName;
import flash.geom.Rectangle;
import flash.sensors.Accelerometer;

public class Bolhas extends MovieClip 
{
var mouse:Mouse1;
var nextObject:Timer;
var nextNivel:Timer;
var objects:Array = new Array();
var score:int = 0;
var nivel:int = 1;
var stopButton:SimpleButton;
const speed:Number = 5.0;
public function Bolhas() {}
public function iniciarJogo():Bolhas {
// constructor code
mouse = new Mouse1();
mouse.y = 550;
addChildAt(mouse,0);
setNextObject();
setNextNivel();
addEventListener(Event.ENTER_FRAME, moveObjects);
/**
 * codigo adicionado
 * coloquei essa parte do startDrag aqui pq isso não tem necessidade de ficar 
em loop
 */
var rectangle:Rectangle = new Rectangle (25,70,750,450);
mouse.startDrag(true, rectangle);
mouse.mouseEnabled = false;
this.mouseEnabled = false;
/** + **/
return this;
jogo.pararJogo(jogo);
}
public function setNextObject() {
nextObject = new Timer(2000-Math.random()*1000,1);
nextObject.addEventListener(TimerEvent.TIMER_COMPLETE,newObject);
nextObject.start();
}
public function setNextNivel() {
nextNivel = new Timer(5,1);
nextNivel.addEventListener(TimerEvent.TIMER,newNivel);
nextNivel.start();
}
public function newObject(e:Event) {
var newObject:MovieClip = new Bolha();
//newObject.x = Math.random() * 500;
newObject.x = (Math.random()*500) + 100;
newObject.y = (Math.random()*100) + 500;
 //newObject.scaleX = (Math.random()*50) + 80;
//newObject.scaleY = newObject.scaleX; 
   addChild(newObject);
objects.push(newObject);
setNextObject();
}
public function newNivel(e:TimerEvent) {
this.nivel++;
//setNextNivel();
}
public function moveObjects(e:Event) {
for(var i:int=objects.length-1;i=0;i--) {
objects[i].y -= speed + nivel * 2;
//if (objects[i].y  500) {
//removeChild(objects[i]);
//objects.splice(i,1);
//}
if (objects[i].hitTestObject(mouse)) {
trace(mouse);
score += 5;
var be:MovieClip = new bolhaEstourada();
be.y = objects[i].y;
be.x = objects[i].x;
removeChild(objects[i]);
addChild(be);
be.gotoAndPlay(2);
objects.splice(i,1);
}
trace(Score: +score);
}
}
public function pararJogo(game:Bolhas){
mouse   = null;
objects = new Array();
nivel   = 1;
score   = 0;
removeChild(game);
}
}
}

TypeError: Error # 2007: Parameter hitTestObject must not be null.
at flash.display:: DisplayObject / _hitTest ()
at flash.display:: DisplayObject / hitTestObject ()
Bubbles at / moveObjects ()

I would like you to show a possible solution to the problem.

Now, thank you.

Renata




___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Help with code

2011-02-12 Thread Gerry Beauregard
Hi Renata,

 TypeError: Error # 2007: Parameter hitTestObject must not be null.


The argument to hitTestObject() is 'mouse'.  You get the error because the 
'mouse' argument to hitTestObject() is null.  Since mouse is constructed in 
function iniciarJogo(), my guess is that iniciarJogo() never gets called. An 
easy fix would be to call iniciarJogo from the constructor of the Bolhas class, 
like this:

public function Bolhas()
{
   iniciarJogo();
}

-Gerry



___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders