Copy link to clipboard
Copied
Hi, I need a solution for my script for school assignment.
This is my codes:
stop();
var kanan:Boolean = false;
var kiri:Boolean = false;
var jumlah:int = 0;
var n=0;
var t=3;
kalah.visible = false;
mulai.addEventListener(MouseEvent.CLICK, mulaimain);
function mulaimain(event:MouseEvent):void
{
kalah.visible = false;
mulai.visible = false;
home.visible = false;
n=0; score.text=String(n);
t=3; lives.text=String(t);
stage.addEventListener (KeyboardEvent.KEY_DOWN, tekantombol);
stage.addEventListener (KeyboardEvent.KEY_UP, lepastombol);
cacto.addEventListener(Event.ENTER_FRAME,jalan);
taco.addEventListener(Event.ENTER_FRAME,jatuh);
heart.addEventListener(Event.ENTER_FRAME,jatuhhati);
function tekantombol (event:KeyboardEvent):void
{
switch (event.keyCode)
{
case Keyboard.RIGHT :{kanan = true;break;}
case Keyboard.LEFT :{kiri = true;break;}
}
}
function lepastombol (event:KeyboardEvent):void
{
cacto.gotoAndPlay(1);
switch (event.keyCode)
{
case Keyboard.RIGHT :{kanan = false; jumlah=0;break;}
case Keyboard.LEFT :{kiri = false; jumlah=0;break;}
}
}
function jalan (event:Event) :void
{
cacto.x+=jumlah;
if (kanan){cacto.gotoAndStop(3); jumlah=11;}
if (kiri){cacto.gotoAndStop(2); jumlah=-11;}
if (cacto.x>=997){cacto.x=-10;}
if (cacto.x<=-37){cacto.x=977;}
}
function jatuh(event:Event):void
{
taco.y+=7;
if(taco.y>=390)
{
t=t-1;lives.text=String(t);
taco.y=-2;
taco.x=Math.floor(Math.random()*800);
}
if(taco.hitTestObject(cacto))
{
n=n+1;score.text=String(n);
taco.y=-2;
taco.x=Math.floor(Math.random()*800);
}
if(t==0)
{
cacto.removeEventListener (Event.ENTER_FRAME,jalan);
taco.removeEventListener (Event.ENTER_FRAME,jatuh);
kalah.visible = true;
mulai.visible = true;
}
function jatuhhati(event:Event):void
{
heart.y+=12;
if(heart.y>=390)
{
heart.y=-30;
heart.x=Math.floor(Math.random()*800);
}
if(heart.hitTestObject(cacto))
{
t=t+1;lives.text=String(t);
heart.y=-30;
heart.x=Math.floor(Math.random()*800);
}
}
}
}
Scene 1, Layer 'Actions', Frame 1, Line 26 | 1120: Access of undefined property jatuhhati. |
and this Output:
ReferenceError: Error #1065: Variable TCMText is not defined.
Can somebody help me?
For the 1120 error you appear to have the jatuhhati function nested within another function. The compiler cannot see it due to that. You should never nest named functions within other functions. Get it out on its own so that it can be seen when the listener assignment that uses it gets compiled.
As far as the 1065 error goes I cannot see any such object named in your code. This usually makes me conclude that there is some component you are using that has such a textfield.
One thing yoiu should
...Copy link to clipboard
Copied
For the 1120 error you appear to have the jatuhhati function nested within another function. The compiler cannot see it due to that. You should never nest named functions within other functions. Get it out on its own so that it can be seen when the listener assignment that uses it gets compiled.
As far as the 1065 error goes I cannot see any such object named in your code. This usually makes me conclude that there is some component you are using that has such a textfield.
One thing yoiu should always do when you start getting errors is to go into your Flash Publish Settings and select the option to Permit Debugging. This can help by pointing to more specific information in the error messages you get, such as line numbers.
Copy link to clipboard
Copied
Thank you very much! I moved my jatuhhati function out and it works. Thanks a lot, Ned!
Copy link to clipboard
Copied
You're welcome
Find more inspiration, events, and resources on the new Adobe Community
Explore Now