Copy link to clipboard
Copied
Hi ! Im new here, and i got a really irritating problem ,
I have a MovieClip called testCam in the 2nd frame on the stage, in testCam MovieClip i have Button, Movie Clip ect. i crating a seperated map about 27 frames, and each frame have a same MovieClip, so i made a function :
function addMovement():void{
addEventListener(Event.ENTER_FRAME, movement);
stage.addEventListener(KeyboardEvent.KEY_DOWN, pencet);
stage.addEventListener(KeyboardEvent.KEY_UP, angkat);
testCam.bag1.addEventListener(MouseEvent.CLICK, goToInventory);
}
and at each frame i just called addMovement to get a same function.
so i created all the frame, with the testCam, and called addMovement(); each frame, everything was normal, until i make a button inside the testCam Movie Clip.
I have a MC named Hoe, and a MC named Tool Box, i created button with Tool Box behind the Hoe, i think i'll be normal, because no Code on both MC, but all i get is, error1009:Error #1009: Cannot access a property or method of a null object reference.
When i use Ctrl+Shift+Enter, its point to this :
testCam.bag1.addEventListener(MouseEvent.CLICK, goToInventory);
I was check thousand times, and testCam is exist in stage, but after i put the new button there it's got error.
I try a simple experiment, i trace the testCam is null or not, and its strange, when i delete the new button there, its said testCam is exist, but after i put that new button its said testCam is null.
Please help me , sorry for my bad english.
Copy link to clipboard
Copied
Where is the code and where is the object? Have you traced both the movieclip and the button inside it?
Copy link to clipboard
Copied
Here is all the related code :
Movement :
function movement(e):void{
testCam.placeText.text = placeStatus;
//testCam.placeText.text = currentFrame;
if(atas == true && testCam.y > 0 + testCam.height/2){
testCam.y -= 3;
myCursor.y -= 3;
}
if(bawah == true && testCam.y < 600 - testCam.height/2){
testCam.y += 3;
myCursor.y += 3;
}
if(kanan == true && testCam.x < 800 - testCam.width/2){
testCam.x += 3;
myCursor.x += 3;
}
if(kiri == true && testCam.x > 0 + testCam.width/2){
testCam.x -= 3;
myCursor.x -= 3;
}
if(cursorStatus == "Hoe"){
myCursor.cursorHoe.gotoAndStop(hoeLevel);
}
testCam.coinUI.moneyText.text = money;
testCam.mineralUI.mineralText.text = mineral;
dateSystem(testCam.hariText,testCam.tahunText,testCam.jamText);
dayNight();
energyCalculation();
testCam.energyTank.energyText.text = energyPercent+"%";
hungerCalculation();
testCam.hungerTank.hungerText.text = hungerPercent+"%";
}
Pencet & Angkat Function :
function pencet(e:KeyboardEvent):void{
if(e.keyCode == 87 || e.keyCode == Keyboard.UP){
atas = true;
}
if(e.keyCode == 83 || e.keyCode == Keyboard.DOWN){
bawah = true;
}
if(e.keyCode == 65 || e.keyCode == Keyboard.LEFT){
kiri = true;
}
if(e.keyCode == 68 || e.keyCode == Keyboard.RIGHT){
kanan = true;
}
}
function angkat(e:KeyboardEvent):void{
if(e.keyCode == 87 || e.keyCode == Keyboard.UP){
atas = false;
}
if(e.keyCode == 83 || e.keyCode == Keyboard.DOWN){
bawah = false;
}
if(e.keyCode == 65 || e.keyCode == Keyboard.LEFT){
kiri = false;
}
if(e.keyCode == 68 || e.keyCode == Keyboard.RIGHT){
kanan = false;
}
}
goToInventory Function :
function inventoryDirect():void{
normalCursor();
energy += eConsume;
tempCamX = testCam.x;
tempCamY = testCam.y;
assignCam = true;
beforeWay = placeStatus;
placeStatus = "Inventory";
stopMovement();
gotoAndStop(3);
}
yeah, it's error 1009 when i trace the button and it's said null when i traced the testCam, with trace(testCam == null), its come out with true.
The code and the object is in the same frame.
Copy link to clipboard
Copied
Does the object also exist in frame 1? If it does, does it have the instance name assigned in frame 1?
Copy link to clipboard
Copied
Nope the button just appear in frame 2 to frame 27 , inside the testCam, i mean testCam is appear in every frame, the strange thing is when the button created and put inside the testCam MC, its error, i just do another experiment, when i made change the Hoe , and Tool Box into ghrapic, then made the button from both, its working, seems AS3 have an exceptional with double MC in one button ?
Copy link to clipboard
Copied
If adding the button in frame 2 of testCam is leading to the error, it is probably because you are trying to target testCam's button while it is not yet present. If you want to target a button inside a movieclip, that button needs to be present when the code executes. If the button is in frame 2 and the code is executing while the movieclip is still at frame 1 then you get an error.
Copy link to clipboard
Copied
no, the condition it's like this :
1.I set up the function addMovement to be called if just the testCam exist.
2.The button i put it's not have any code or instance name yet, I just create it to put at the testCam.
Its like imagine that you have non error project first, then you just create a button, and you put inside the testCam, then you want to see how the button looks like if you over in to it, and suddenly the error appear.
The button that i used(The error one) is is from Hoe & Tool box MovieClip, that just have one frame and just a graphic inside, (I made it to movie clip to enable the glow), But if i used a button that i made directly, not from another movie clip, it's working, so it's like, i can't use a button that have Movie Clip inside, must graphic or make it directly.
this is the error :
TypeError: Error #1009: Cannot access a property or method of a null object reference.
1 at HarvestmoonAlphaTest_fla::MainTimeline/addMovement()[HarvestmoonAlphaTest_fla.MainTimeline::frame1:802]
2 at HarvestmoonAlphaTest_fla::MainTimeline/mulai()[HarvestmoonAlphaTest_fla.MainTimeline::frame2:9]
3 at HarvestmoonAlphaTest_fla::MainTimeline/frame2()[HarvestmoonAlphaTest_fla.MainTimeline::frame2:68]
4 at flash.display::Sprite/constructChildren()
5 at flash.display::Sprite()
6 at flash.display::MovieClip()
7 at HarvestmoonAlphaTest_fla::VCam_AS3_8()
8 at flash.display::MovieClip/gotoAndStop()
9 at HarvestmoonAlphaTest_fla::MainTimeline/gerakanMouse()[HarvestmoonAlphaTest_fla.MainTimeline::frame1:681]
before i add that strange button its working as usual, but after i put it (without code or any instance name, just the Buttoon its self), the error point at this :
testCam.bag1.addEventListener(MouseEvent.CLICK, goToInventory);
the button i used is a diffrent button from bag1 button
Copy link to clipboard
Copied
One thing you might try is adding a FRAME_CONSTRUCTED event listener in frame 2 and wait to add the click listener to testCam.bag1 until after that is called. In your stack trace exists at flash.display::Sprite/constructChildren() so I am thinking that for whatever reason your frame objects are not yet ready before this ActionScript is being called.
Although what is odd to me is generally the FRAME_CONSTRUCTED event happens before any timeline script even executes - so this may not do anything at all but I am curious why ActionScript is being executed in a constructChildren() stack trace.
addEventListener(Event.FRAME_CONSTRUCTED, frameConstructed);
function frameConstructred(e:Event):void
{
// Call whatever is at frame2:68 or frame2:9 here
}
Copy link to clipboard
Copied
Can you explain difference between FRAME_CONSTRUCTED and ENTER_FRAME ? Which better, and it's possible if i change all the ENTER_FRAME into FRAME_CONSTRUCTED ?
Thanks
Copy link to clipboard
Copied
and in its error its said
at flash.display::Sprite/constructChildren()
at flash.display::Sprite()
at flash.display::MovieClip()
Copy link to clipboard
Copied
if you could, i'll send to your e-mail my project, please help me for this
Find more inspiration, events, and resources on the new Adobe Community
Explore Now