Chapter two on page 54
Greetings everybody
I am working through the book
to learn more.
Unfortanally i got stuck on page 54
I supose to make an event lissener
towards BOTH cubes you made with just
pure programming. As you can read on
that page the lissener seeks for wether
you click with your mouse either on one
of those cubes and if so then place the
third sprite you made (the cirkel) on
100,100 (center) of that cube.
Everything worked fine except for when i
adding the lissener it wont work.
It works adding all three items on the right
possition yet when i add the five line's i get
an error. Could anybody help me?
*error* Type was not found or was not a compile-time constant:
MouseEvent function clickSprite(event:MouseEvent){
PS: i already checked wether the name of the command is the same
(in case of the book its called clickSprite)
and i already checked wether the name of the sprite you want to
give a lissener is correct (in the case of the book its called
sprite1 / sprite2 :::: wich you give a lissener)
Also i re-readed everything yet it just keeps whining with the
same error
Also if this helps YES the programming was made in an AS file wich is
linked to a FLA file with the same name. (wich you learn when you start
with the hello world tradition)
Furtermore here is my programming
(I dont mind if you copy it to try it out since its a practice from a book so
all the credits go's towards the writer and maker of the book
Also to make it more clearly whats wrong if you remove the text wich is noted again
all the way below you'll notice if you run it again it works perfectly)
package {
import flash.display.*;
import flash.text.*;
public class BookLessonMultipleSprites2 extends MovieClip {
public function BookLessonMultipleSprites2() {
//Sprite 1 Cube 01
var sprite1:Sprite = new Sprite();
sprite1.graphics.lineStyle(2,0x000000);
sprite1.graphics.beginFill(0xcccccc);
sprite1.graphics.drawRect(0,0,200,200);
sprite1.x = 50;
sprite1.y = 50;
addChild(sprite1);
//Sprite 1 Cube 01
//Sprite 2 Cube 02
var sprite2:Sprite = new Sprite();
sprite2.graphics.lineStyle(2,0x000000);
sprite2.graphics.beginFill(0xcccccc);
sprite2.graphics.drawRect(0,0,200,200);
sprite2.x = 300;
sprite2.y = 50;
addChild(sprite2);
//Sprite 2 Cube 02
//Sprite 3 Cirkel 01
var sprite3:Sprite = new Sprite();
sprite3.graphics.lineStyle(2,0x000000);
sprite3.graphics.beginFill(0x333333);
sprite3.graphics.drawCircle(0,0,25);
sprite3.x = 100;
sprite3.y = 100;
addChild(sprite3);
//Sprite 3 Cirkel 01
sprite1.addEventListener(MouseEvent.CLICK, clickSprite);
sprite2.addEventListener(MouseEvent.CLICK, clickSprite);
function clickSprite(event:MouseEvent){
event.currentTarget.addChild(sprite3);
}
}}}
This is the text that gives the error
sprite1.addEventListener(MouseEvent.CLICK, clickSprite);
sprite2.addEventListener(MouseEvent.CLICK, clickSprite);
function clickSprite(event:MouseEvent){
event.currentTarget.addChild(sprite3);
}
If you DO CUT this part out and run it agian you'll notice it works more then fine
Thank you in progress
Copyright Gary Rosenzweig
