• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
May 10, 2023 May 10, 2023

Copy link to clipboard

Copied

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

TOPICS
ActionScript , Code , Error

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2023 May 11, 2023

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 11, 2023 May 11, 2023

Copy link to clipboard

Copied

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;
}

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 12, 2023 May 12, 2023

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 12, 2023 May 12, 2023

Copy link to clipboard

Copied

https://drive.google.com/file/d/1LkNOO8jNBOp8HGow_L8gi-wtiJjfz88Y/view 

 

here u can see this record, the problem is shuffle button can't work. please help me this is for my college project

thanks

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 12, 2023 May 12, 2023

Copy link to clipboard

Copied

you've showed two different errors (and an unhelpful video), so far.

 

start by concentrating on solving one error.

 

eg, if you can still create your original error message by some series of interactions while testing, show the lines of code surrounding line 4, frame 68.  eg, show lines 1 through 10 and indicate which is line 4.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 12, 2023 May 12, 2023

Copy link to clipboard

Copied

sorry, on line 4 and frame 68 it's been solved because only the button forgot to give an instance name, and now I only need the code for the button to randomize the puzzle

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 12, 2023 May 12, 2023

Copy link to clipboard

Copied

excellent.

 

now do the same for any other errors (eg, frame 68, line 237) with which you want help.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 12, 2023 May 12, 2023

Copy link to clipboard

Copied

do you know the code to randomize the puzzle pls?

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 12, 2023 May 12, 2023

Copy link to clipboard

Copied

generally, add on-stage references to an array and then randomize using a shuffle function.

 

shuffle(your_array); 

// your_array is now shuffled

 

function shuffle(a:Array) {
var p:int;
var t:*;
var ivar:int;
for (ivar = a.length-1; ivar>=0; ivar--) {
p=Math.floor((ivar+1)*Math.random());
t = a[ivar];
a[ivar] = a[p];
a[p] = t;
}
}

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 12, 2023 May 12, 2023

Copy link to clipboard

Copied

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{
acakbtn.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;
}
}

 

I have tried but still, is there something wrong? or does the shuffle button have to be in a movie clip with the puzzle?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 12, 2023 May 12, 2023

Copy link to clipboard

Copied

LATEST

be careful about the children in game. make sure that includes what you want and doesn't include unwanted references.

 

also, all those event listeners are unnecessary.  you only need one when a puzzle piece detects a mousedown

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 11, 2023 May 11, 2023

Copy link to clipboard

Copied

what's the code surrounding that line?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines