TypeError: Error #1034: Type Coercion failed on Accordion panels - actionscript-3

i use an ready Accordion Panel in Flash ( here )
now when i add any button on this frame i get this error when i click Accordion tabs :
TypeError: Error #1034: Type Coercion failed: cannot convert
flash.display::SimpleButton#48596ab9 to flash.display.MovieClip.
and when i add movieclip to the stage i get this error right after click on any Accordion panels :
TypeError: Error #1010: A term is undefined and has no properties.
at mobver2_fla::MainTimeline/onClick()
here is the main script for Accordion panel :
import gs.*;
import gs.easing.*;
panel1.props = {ly:53, ry:650, ind:1};
panel2.props = {ly:115, ry:700, ind:2};
panel3.props = {ly:169, ry:750, ind:3};
panel1.addEventListener(MouseEvent.CLICK, onClick);
panel2.addEventListener(MouseEvent.CLICK, onClick);
panel3.addEventListener(MouseEvent.CLICK, onClick);
function onClick(e:MouseEvent):void
{
var clicked:MovieClip = MovieClip(e.target);
for(var i:int=0; i<numChildren; i++)
{
var mc:MovieClip = MovieClip(getChildAt(i));
if(mc.props.ind <= clicked.props.ind)
TweenLite.to(mc, 1, {y:mc.props.ly, ease:Bounce.easeOut});
else
TweenLite.to(mc, 1, {y:mc.props.ry, ease:Bounce.easeOut});
}
}
it seems this script effect on all movieclip or buttons in Frame , but i cant figure it out how i must separate other buttons and movieclips from this . i really need to add some button and movie clip to these panels and frame

The error says it all - you try to cast a button to a MovieClip, and SimpleButton is NOT a MovieClip.
This has nothing to do with the Accordion.
You need to change this line:
var clicked:MovieClip = MovieClip(e.target);
Start using debugger and traces to see what are you actually doing. Also - enable permit debugging to see on which line the error is.
We cannot help you every time you do something wrong, as this is not a common problem, nor pattern oriented, it's just a simple error of yours.

Related

How to fix 'TypeError: Error #1009' error in ActionScript3.0 Adobe Animate

I'm setting up a button on the first frame which when clicked will transfer the user to the 2nd frame using this code:
stop();
Btn_1.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndPlayFromFrame_2);
function fl_ClickToGoToAndPlayFromFrame_2(event:MouseEvent):void
{
gotoAndPlay(2);
}
and on the second frame, I set up a dynamic text that will perform a countdown using this code:
var myTimer:Timer = new Timer(1000,60); // every second for 60 seconds
myTimer.addEventListener(TimerEvent.TIMER, onTimer);
myTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onComplete);
myTimer.start();
function onTimer(e: TimerEvent):void {
countdown_text.text = String(myTimer.repeatCount - myTimer.currentCount);
}
function onComplete(e: TimerEvent):void{
gotoAndStop(3);
}
the thing is keep getting TypeError: Error #1009 message after debugging it. I know the fault is in line 7 of the 2nd code but I have no idea what is wrong with it. Pls help!
I should see your source fla, but it is most likely related to countdown_text not being accessible in that frame. Error description is "Cannot access a property or method of a null object reference", that means it cannot find the reference which is "countdown_text".
It is very very bad practice to write AS directly in frames. Convert code into a class and assign it as a document class.
You can find Adobe documentation for document class here: https://helpx.adobe.com/animate/using/actionscript-publish-settings.html

AS3 - Error #1009 and cannot find cause of issue

Using AS3 in Animate CC, I get this error:
Error #1009: Cannot access a property or method of a null object reference.
I have read through all the work-through for this error On Stack Overflow but I still can't figure this one out. Any help would be a blessing.
I have a navigation panel of 96 buttons I'm attempting that when user clicks a movie from the library appears. A couple problems, first the error 1009 and also secondly when a new MovieClip appears the current one needs to go away.
Label for one of the buttons
btn_SAFER_25_1Jan
Label for Movie clip Symbol property
mcSaf_Jan01_25
Label for Name of Movie Symbol Class
Saf_Jan01_25
Code below, each frame of timeline that suppose to load each movie has similar, this one is for Jan 1 25
stop();
var saf_Jan01_25:Saf_Jan01_25=new Saf_Jan01_25;
addChild(saf_Jan01_25);
addChildAt(saf_Jan01_25,0);
saf_Jan01_25.x=394;//sets the x position
saf_Jan01_25.x=344;//sets the y position
saf_Jan01_25.visible = true;
saf_Jan01_100.visible = false;
saf_Jan01_250.visible = false;
saf_Jan01_500.visible = false;
script below is on timeline of for each navigation button
btn_SAFER_25_1Jan.addEventListner(MouseEvent.CLICK, fl_MouseOverHandler2);
btn_SAFER_25_1Jan.enabled = true;
function fl_MouseOverHandler2(eventMouseEvent):void
{
{
gotoAndPlay(2);
}
trace("Click");
}
btn_SAFER_100_1Jan.addEventListner(MouseEvent.CLICK, fl_MouseOverHandler3);
btn_SAFER_100_1Jan.enabled = true;
function fl_MouseOverHandler3(eventMouseEvent):void
{
{
gotoAndPlay(3);
}
trace("Click");
}

How to fix AS3 TypeError: Error #1009: Cannot access a property or method of a null object reference?

I am getting this error:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Skool_fla::MainTimeline/frame1()[Skool_fla.MainTimeline::frame1:10]
at flash.display::MovieClip/gotoAndStop()
at Skool_fla::MainTimeline/goback()[Skool_fla.MainTimeline::frame2:22]
What is causing this error and how do I fix it?
This is my code for both the frames:
Frame 1: This is the main menu screen where you can access the credit section
import flash.events.MouseEvent;
//setting up the variables
//events
//stop the timeline
stop();
//the play button
play_btn.addEventListener(MouseEvent.CLICK, playani);
function playani(e:MouseEvent)
{
//asking it to progress to the load menu
gotoAndStop(3);
}
//the credits button
credit_btn.addEventListener(MouseEvent.CLICK, creditslide);
function creditslide(e:MouseEvent)
{
//asking it to go the credits frame
gotoAndStop(2);
}
Frame 2: This is where the credits appear
//
//
//all the imports
//events
var credit:credits_bck = new credits_bck ();
var credits_name: credit_nm = new credit_nm ();
var back_butn: back_button = new back_button ();
addChild (credit);
addChild (credits_name);
addChild (back_butn);
back_butn.addEventListener(MouseEvent.CLICK,goback);
function goback(G:MouseEvent)
{
removeChild (credit);
removeChild (credits_name);
gotoAndStop(1);
}
Either play_btn or back_butn is null. Your error message's line numbers don't correspond to your code so it's hard to say. But the gist is you're trying to access a property of something that isn't anything. Check to make sure you're initializing your variables/references properly.
Maybe your problem is Flash bug too.
In my FLA there was a layer with one empty keyframe. If I puted a vector graphics on it, the error was gone. If there was one or multiple MovieClips and there was no vector graphic - the error was there again.
Then I made a new layer and copy pasted all the objects from damaged layer to new and deleted the damaged layer. It solved the problem.
NOTE: Don't copy the keyframes. Only copy the contents.
Now my project is much more complicated and sadly the error came back again.
Test movie frequently and if the error comes back, check the last keyframes and layers you created.

Removing an event listener as well as a sprite at the same time AS3

I’m having trouble removing the an event listener as well as the sprite at the same time. I currently get an error:
TypeError: Error #1009: Cannot access
a property or method of a null object
reference.
And if I comment out removeChild, I have no error but, obviously, the sprite remains on the screen. Any ideas how I can rid myself of that error?
//Bullet extends Sprite Class
bullet:Bullet = new Bullet();
mc.addChild(bullet);
bullet.addEventListener(Event.ENTER_FRAME, shoot);
function shoot(e:Event):void {
var shot:Bullet = e.currentTarget as Bullet;
//check shot is outside the frame
if (shot.x < 0 - shot.width || shot.x > stage.stageWidth || shot.y > 525)
{
//trying to remove the thing and it's listener
e.currentTarget.removeEventListener(e.type,arguments.callee);
e.currentTarget.parent.removeChild(shot);
}
else
{
shot.setInMotion();
}
}
Apart from a missing var before bullet:Bullet, I don't see anything wrong in the example code. You should set a breakpoint right after:
var shot:Bullet = e.currentTarget as Bullet;
And figure out why shot is null. I suspect there is something amiss in a piece of code outside of the little bit you're providing as the example. If the code is working with only the removeChild line commented out, it tells me that e.currentTarget is not null, but that it's also not a reference to an instance of type Bullet (i.e. the "as" cast is returning null).
Try reversing these lines
Maybe the reference to e.currentTarget is getting lost through the object references
e.currentTarget.removeEventListener(e.type,arguments.callee);
e.currentTarget.parent.removeChild(shot);
to
e.currentTarget.parent.removeChild(shot);
e.currentTarget.removeEventListener(e.type,arguments.callee);

Error #1034 while running flash application

Alright, I know that this error is occurring because of something to do with addchild() function. On frame 2. How do I know? Because when I remove the snippets of code that dynamically place an object onto the stage it works fine. The error is below and the source code for frame 2 is below the error messages.
Error Code
TypeError: Error #1034: Type Coercion failed: cannot convert 0 to flash.display.DisplayObject.
at fl.motion::AnimatorBase/play()
at fl.motion::AnimatorBase$/processCurrentFrame()
at fl.motion::AnimatorBase/handleEnterFrame()
at flash.display::MovieClip/nextFrame()
at Lemonade_fla::MainTimeline/begin()[Lemonade_fla.MainTimeline::frame1:27]
TypeError: Error #1034: Type Coercion failed: cannot convert 0 to
FRAME 2 CODE
flash.display.DisplayObject.
stop();
var guide_tut:guide = new guide();
addChild(guide_tut);
//stand.addEventListener(MouseEvent.CLICK, check);
addEventListener(Event.ENTER_FRAME, check);
function check(ev : Event) : void {
cash.text.text = cash1;
lemons_count.text.text = lemons1;
cups_count.text.text = cups;
straws_count.text.text = straws;
ice_count.text.text = ice;
}
shop_mc.addEventListener(MouseEvent.CLICK, shopnow);
function shopnow(event:MouseEvent):void{
nextFrame();
}
1) I ran your code it works fine, the only place the error could be generated is:
flash.display.DisplayObject.
should be: flash.display.DisplayObject;
but you don't need it.
and
var guide_tut:guide = new guide();
addChild(guide_tut);
I ran it with just an empty mc, it works fine.
2) no reason to have (i know its commented out) but there never a reason to have
stand.addEventListener(MouseEvent.CLICK, check) ever since check is EnterFrame
basically you're error is within either display, most likely you're not extending the class from MovieClip
public class guide extends MovieClip
instead of movieclip it can be sprite or other displayobject...