Skip to main content
Participating Frequently
May 11, 2023
Question

TypeError: Error #1009: Cannot access a property or method of a null object reference. at apkandro1

  • May 11, 2023
  • 2 replies
  • 1456 views

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at apkandro1_fla::MainTimeline/frame68()[apkandro1_fla.MainTimeline::frame68:4]
at flash.display::MovieClip/gotoAndStop()
at MPI/doBtn()

 

can anyone help me? i have this problem

This topic has been closed for replies.

2 replies

kglad
Community Expert
Community Expert
May 11, 2023

what's the code surrounding that line?

JoãoCésar17023019
Community Expert
Community Expert
May 11, 2023

Hi.

 

You have an invalid reference in line 4 of frame 68 (in the Actions Panel). This is usually due to incorrectly named instances and/or variables or because the instance you're trying to access doesn't exist at that frame.

 

But we need more details to help you. Can you show us the code and the timeline at that point?

Regards,

JC

delxd_Author
Participating Frequently
May 12, 2023

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at apkandro1_fla::MainTimeline/frame68()[apkandro1_fla.MainTimeline::frame68:237]
at flash.display::MovieClip/gotoAndStop()
at MPI/doBtn()

 

this is the problem and this code

import flash.events.MouseEvent;
import flash.display.MovieClip;
import flash.events.Event;

var game:MovieClip;
var bgPuzzle:MovieClip;
var lebarPuzzle:int = 4;
var tinggiPuzzle:int = 3;
var ukuranPuzzle:int = 100;
var puzzleX:int = 250;
var puzzleY:int = 150;
var puzzleTimer:Boolean = false;
var gambarPuzzle:String = "gambar1";
var pengaturWaktu:MovieClip = null;

var efekTimbul:BevelFilter = new BevelFilter();
efekTimbul.type = BitmapFilterType.INNER;
efekTimbul.distance = 1;
efekTimbul.highlightColor = 0xFFFFFF;
efekTimbul.shadowColor = 0x000000;
efekTimbul.blurX = 3;
efekTimbul.blurY = 3;

var gameAktif:Boolean = false;
var kepingTerpilih:Boolean = false;
var drag:Boolean = false;
var puzzleBenar:int = 0;
var fps:int = 30; //frame per second
var waktu:int = 0;
var waktuGame:int = lebarPuzzle*tinggiPuzzle*10; //waktu permainan dalam detik
var waktuMaks:int = waktuGame;
var hasilMC:MovieClip;


function buatPuzzle(px:int, py:int):void{
//movieclip game digunakan sebagai container untuk mempermudah pengaturan
bgPuzzle = new MovieClip();
bgPuzzle.x = px;
bgPuzzle.y = py;
bgPuzzle.alpha = 0.3;
addChild(bgPuzzle);
game = new MovieClip();
game.x = px;
game.y = py;
addChild(game);
var skala:Number = ukuranPuzzle/100;
//tambahkan puzzle dengan operasi for
for (var i:int = 0; i < tinggiPuzzle;i++){
for (var j:int = 0; j < lebarPuzzle; j++){
//membuat pola pembantu peletakan puzzle
var pola:kepingPuzzle = new kepingPuzzle;
pola.x = j*100*skala;
pola.y = i*100*skala;
pola.scaleX = skala;
pola.scaleY = skala;
aturKeping(pola, i, j);
bgPuzzle.addChild(pola);
//membuat container untuk mengatur bentuk kepingan dan gambar
var puzzle1:MovieClip = new MovieClip;
puzzle1.x = j*100*skala;
puzzle1.y = i*100*skala;
game.addChild(puzzle1);
//menambahkan gambar ke dalam puzzle
var pic:Class = getDefinitionByName(gambarPuzzle) as Class;
var gambar1:MovieClip = new pic;
gambar1.x = -j*100*skala-50*skala;
gambar1.y = -i*100*skala-50*skala;
puzzle1.addChild(gambar1);
//menambahkan bentuk kepingan
var keping:kepingPuzzle = new kepingPuzzle;
keping.scaleX = skala;
keping.scaleY = skala;
aturKeping(kepingPuzzle, i, j);
puzzle1.addChild(keping);
//membentuk gambar sesuai kepingan dengan mask
gambar1.mask = keping;
//menambahkan efek embos dan outline
gambar1.filters = [efekTimbul];
}
}
}

function aturKeping(ob:Object, i:int, j:int):void{
//mengatur kepingan bagian atas
if (i == 0 && j == 0) ob.gotoAndStop(1);
if (i == 0 && j > 0 && j < lebarPuzzle-1) ob.gotoAndStop(2);
if (i == 0 && j == lebarPuzzle-1 ) ob.gotoAndStop(3);
//mengatur kepingan bagian tengah
if (i > 0 && i < tinggiPuzzle - 1 && j == 0) ob.gotoAndStop(4);
if (i > 0 && i < tinggiPuzzle - 1 && j > 0 && j < lebarPuzzle-1) ob.gotoAndStop(5);
if (i > 0 && i < tinggiPuzzle - 1 && j == lebarPuzzle-1 ) ob.gotoAndStop(6);
//mengatur kepingan bagian tengah
if (i == tinggiPuzzle - 1 && j == 0) ob.gotoAndStop(7);
if (i == tinggiPuzzle - 1 && j > 0 && j < lebarPuzzle-1) ob.gotoAndStop(8);
if (i == tinggiPuzzle - 1 && j == lebarPuzzle-1 ) ob.gotoAndStop(9);
}

function aturWaktu(e:Event):void{
if (gameAktif){
waktu++;
if (waktu > fps){
waktu = 0;
waktuGame--;
if (waktuGame <= 0){
//waktu habis
tampilkanHasil(false);
}
}
//tampilkan dalam movieclip pengaturWaktu
if (puzzleTimer && pengaturWaktu!=null) pengaturWaktu.barMC.scaleX = waktuGame/waktuMaks;
}
}

function tampilkanHasil(menang:Boolean):void{
gameAktif = false;
//hasil jika menang
if (menang){
hasilMC = new scoreMC;
//menentukan bintang
if (waktuGame/waktuMaks > 0.5){
hasilMC.bintang.gotoAndStop(3);
}else if (waktuGame/waktuMaks > 0.3){
hasilMC.bintang.gotoAndStop(2);
}else{
hasilMC.bintang.gotoAndStop(1);
}
}else{
hasilMC = new gagalMC;
}
hasilMC.x = 400;
hasilMC.y = 240;
hasilMC.retryBtn.addEventListener(MouseEvent.CLICK, ulangi);
addChild(hasilMC);
}


function jalankanGame():void{
waktuGame = waktuMaks;
waktu = 0;
puzzleBenar = 0;
if (puzzleTimer && pengaturWaktu!=null){
pengaturWaktu.addEventListener(Event.ENTER_FRAME, aturWaktu);
}
puzzle1.visible = true;
puzzle1.addEventListener(MouseEvent.CLICK, acakPuzzle);
buatPuzzle(puzzleX, puzzleY);
stage.addEventListener(MouseEvent.MOUSE_DOWN, tekanMouse);
stage.addEventListener(MouseEvent.MOUSE_UP, lepasMouse);
}

function acakPuzzle(e:MouseEvent):void{
puzzle1.visible = false;
gameAktif = true;
for (var i:int = 0; i < game.numChildren; i++){
var ob:Object = game.getChildAt(i);
//menyimpan data awal puzzle
ob.snap = false;
ob.xa = ob.x;
ob.ya = ob.y;
ob.addEventListener(Event.ENTER_FRAME, dragPuzzle);
//mengacak puzzle
ob.x = Math.random()*700+50-game.x;
ob.y = Math.random()*400+50-game.y;
}
}

function dragPuzzle(e:Event):void{
if (gameAktif){
var ob:Object = e.currentTarget;
if (drag && !kepingTerpilih && !ob.snap){
//metode jarak untuk menentukan klik mendekati tengah kepingan
if (ob.hitTestPoint(mouseX, mouseY, true)){
kepingTerpilih = true;
ob.aktif = true;
//letakkan kepingan di layer teratas
game.setChildIndex( DisplayObject(ob), game.numChildren -1 );
}
}
if (ob.aktif){
ob.x = mouseX-game.x;
ob.y = mouseY-game.y;
if (!drag) {
ob.aktif = false;
//tentukan jarak puzzle dengan posisi yang benar
var jarak:Number = Math.sqrt((ob.x - ob.xa)*(ob.x-ob.xa)+(ob.y - ob.ya)*(ob.y-ob.ya));
if (jarak < 10){
ob.x = ob.xa;
ob.y = ob.ya;
ob.snap = true;
puzzleBenar++;
if (puzzleBenar == lebarPuzzle*tinggiPuzzle){
//menang
tampilkanHasil(true);
}
}
}
}
}
}

function hapusPuzzle():void{
//hapus kepingan puzzle di dalam MC game
while(game.numChildren > 0){
var ob:Object = game.getChildAt(game.numChildren-1);
ob.removeEventListener(Event.ENTER_FRAME, dragPuzzle);
game.removeChild(DisplayObject(ob));
}
removeChild(game);
removeChild(bgPuzzle);
stage.removeEventListener(MouseEvent.MOUSE_DOWN, tekanMouse);
stage.removeEventListener(MouseEvent.MOUSE_UP, lepasMouse);
}

function ulangi(e:MouseEvent):void{
//menghapus hasil
if (puzzleTimer && pengaturWaktu!=null){
pengaturWaktu.removeEventListener(Event.ENTER_FRAME, aturWaktu);
}
hasilMC.retryBtn.addEventListener(MouseEvent.CLICK, ulangi);
removeChild(hasilMC);
//mengulangi permainan
hapusPuzzle();
jalankanGame();
}


function tekanMouse(e:MouseEvent):void{
drag = true;
}
function lepasMouse(e:MouseEvent):void{
drag = false;
kepingTerpilih = false;
}

 

 

JoãoCésar17023019
Community Expert
Community Expert
May 12, 2023

Hi.

 

Do you mind testing your project in debug mode (Ctrl + Shift + Enter (Windows) or Cmd + Shift + Return (Mac)) so that we can know the exact line of code that is failing?