How to remove an event listener of Enter Frame

basically, i doing a three level game. 1st level is dodging the stone from sky, Secondly, samsh the wolf head. However, when i enter leve1 2 game, it show me an error.
TypeError: Error #2007: Parameter hitTestObject must be non-null.as:113  Cant access to null object or reference.as.83
I think due to when i enter level 2, the object is not available anymore, so happen this errors,izzit? how i gonna fix this?
package
          import flash.display.MovieClip;
          import flash.events.KeyboardEvent;
          import flash.ui.Keyboard;
          import flash.events.Event;
          import flash.events.MouseEvent;
          import flash.ui.Mouse;
          import flash.utils.Timer;
          import flash.events.TimerEvent;
          import flash.events.Event;
          public class level1 extends MovieClip
                    var vx:int;
                    var vy:int;
                    var collisionHasOccurred:Boolean;
                    var score:uint;
                    public function level1()
                              init();
                    function init():void
                              //Initialize variable
                              vx=0;
                              vy=0;
                              collisionHasOccurred=false;
                              stone.stop();
                              score=0;
                              optionPage.visible=false;
                    //Add event listeners
                    stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
                    stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
                    addEventListener(Event.ENTER_FRAME, onEnterFrame);
                    wolf2.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
                    function onKeyDown(event:KeyboardEvent):void
                              if(event.keyCode==Keyboard.LEFT)
                                        vx=-5;
                              else if (event.keyCode==Keyboard.RIGHT)
                                        vx=5;
                              else if (event.keyCode==Keyboard.UP)
                                        vy=-5;
                              else if (event.keyCode==Keyboard.DOWN)
                                        vy=5;
                    function onKeyUp(event:KeyboardEvent):void
                              if (event.keyCode==Keyboard.LEFT || event.keyCode==Keyboard.RIGHT)
                                        vx=0;
                              else if (event.keyCode==Keyboard.DOWN || event.keyCode==Keyboard.UP)
                              vy=0;
                    function onEnterFrame(event:Event):void
                              trace(player);
                              trace(cursor);
                              trace(aaa);
                              trace(wolf2);
                              trace(wolf);
                              //Move the player
                              player.x+=vx;  <-------------------------------------------------------------this is line 83
                              player.y+=vy;
                              //collision detection
                              if (stone.hitTestObject(player))
                              player.gotoAndStop(3);
                              health.meter.width-=2;
                              if (! collisionHasOccurred)
                                        score++;
                                        messageDisplay.text=String(score);
                                        collisionHasOccurred=true;
                    else
                              player.gotoAndStop(1);
                              collisionHasOccurred=false;
                    if (health.meter.width <=1)
                              New.text="Game Over!";
                              stop();
                              fl_CountDownTimerInstance_3.stop();
                    if (player.hitTestObject(wall))   <-------------------------------------------------this is line 113
                              player.x-=vx;
                              player.y-=vy;
                    if (player.hitTestObject(wallA))
                              player.x-=vx;
                              player.y-=vy;
                    if (player.hitTestObject(wallB))
                              player.x-=vx;
                              player.y-=vy;
                    if (player.hitTestObject(wallC))
                              player.x-=vx;
                              player.y-=vy;
                    if (player.hitTestObject(wallD))
                              player.x-=vx;
                              player.y-=vy;
                    if (player.hitTestObject(wallE))
                              player.x-=vx;
                              player.y-=vy;
                    if (player.hitTestObject(wallF))
                              player.x-=vx;
                              player.y-=vy;
                    if (player.hitTestObject(wallG))
                              player.x-=vx;
                              player.y-=vy;
                    if (player.hitTestObject(wallH))
                              player.x-=vx;
                              player.y-=vy;
                    function fl_MouseClickHandler(event:MouseEvent):void
                    score++;
                    aaa.text=String(score);
                    trace("Mouse clicked");

instead of:
if (player.hitTestObject(wall))
use:
if(player&&wall){
if (player.hitTestObject(wall))

Similar Messages

  • How to remove an event listener

    I have a series of buttons. When a button is clicked a component (instructorView) is loaded into a container named passageContainer:
    passageContainer.addChild(instructorView);
    Each time I load a new component, I remove the old component first:
    passageContainer.removeAllChildren();
    The component includes an eventListener which is triggered when a key is pressed.
    The first time I load a component and press a key the event is triggered once.
    The second time the event is triggered twice.
    The third time the event is triggered three times, and so on.
    I'm almost certain that the eventListeners are not being removed although the components are removed. So the event listeners execute multiple times.
    Is it possible for the eventListeners to remain after the components have been removed? If so, how can I remove them?
    Thanks!

    It means the components are still in the memory, they are tightly coupled, you need to do makesure that the event listeners are loosely coupled/weakreferenced.
    http://www.selikoff.net/2010/09/21/flex-event-handlers-and-weak-references/
    (OR) you have to remove the listeners manually, by doing this.removeEventLIstener(...... on each and every component to all the events that are registered in the component before you remove it from the memory.
    Message was edited by: saisri2k2

  • How to add exiting event listener in javascript

    I am trying to figure out how to add an event listener in javascript for the exiting event when the red x is clicked on a Windows window (top right corner).
    I found this among adobe documentation, but it does not work:
    var app = air.NativeApplication.nativeApplication;
    app.addEventListener(air.Event.EXITING, closeHandler);
    function closeHandler(event) {
      alert("Goodbye.");
    And yes I have the AIRAliases.js included.
    Thanks

    The code posted above is from page 10 of the "HTML Developer’s Guide for ADOBE AIR (prerelease updated 11/16/2009)".
    I am actually exiting the program because I only have one window open and I click on the red x in the top right corner to shut it down... in theory, the example above provided by Adobe, should interrupt the exit sequence by displaying an alert box amd then shut the program down.
    Here's the excerpt from the manual...
    unload events (for body and frameset objects)
    Adobe AIR 1.0 and later
    In the top-level frameset or body tag of a window (including the main window of the application), do not use the unload event to respond to the window (or application) being closed. Instead, use exiting event of the NativeApplication object (to detect when an application is closing). Or use the closing event of the NativeWindow object (to detect when a window is closing). For example, the following JavaScript code displays a message ("Goodbye.") when the user closes the application:
    var app = air.NativeApplication.nativeApplication;
    app.addEventListener(air.Event.EXITING, closeHandler);
    function closeHandler(event)
    alert("Goodbye.");
    However, scripts can successfully respond to the unload event caused by navigation of a frame, iframe, or top-level window content.
    Note: These limitations may be removed in a future version of Adobe AIR.

  • [svn:bz-trunk] 23085: Fix test to explicitly remove an event listener after the test is finished .

    Revision: 23085
    Revision: 23085
    Author:   [email protected]
    Date:     2011-10-21 07:49:33 -0700 (Fri, 21 Oct 2011)
    Log Message:
    Fix test to explicitly remove an event listener after the test is finished. Not doing this was causing the test to throw an RTE.
    Modified Paths:
        blazeds/trunk/qa/apps/qa-regress/testsuites/mxunit/tests/messagingService/security/stream ing-amf/MessagingAuthProSendTest.mxml

    Thanks for the ideas regarding beforeInvoke, Ben.  I will try to check that out.  In my situation, here's essentially how my script is working...
    BeforeSave is invoked.
    Script makes a change to the document, which should be captured in the saved file.
    Document saves.
    Document appears saved for a moment, and then appears unsaved (asterisk in the document title).
    My biggest problem is that this behavior isn't consistent.  I have dozens of users, all running the same script, and the problem only occurs with certain users and at random times. I can move a problematic document from a user's machine to a different machine, and the problem doesn't occur there.  It's very difficult to troubleshoot because I can't reproduce it consistently.

  • Extended Canvas, Event Listener - drag enter

    I'm trying to add an eventListener to my extended Canvas
    Class but seem to be having a slight problem.
    I've created a loop which runs 16 times, adds an instance of
    the canvas to a container and sets an drag enter event listener for
    each one, however when i drag over only one of the canvas' reacts
    to the drag enter (the last instance) - regardless of where i drag
    the object.
    heres some example code
    for(var i = 0; i < 16;i++)
    var foo:extendedCanvasObj = new extendedCanvasObj();
    foo.setstyle.......
    foo.addEventListener(dragEvent.DRAG_ENTER,function(event:DragEvent){
    change the canvas backgroundcolour };
    container.addChild(foo);
    }

    Thanks for the quick reply,
    I understand what you mean, but how would i stop it from doing this?  I want the "new boxes" to know when a drag proxy has entered them but i don't want them to accept a drop.
    Basically i'm building a form builder and the boxes represent fields.  I want them to know when the proxy has just enter them to i can perform a collision detection and move them to create space to drop the new field. 
    Tom

  • How to remove complex event listeners

    circDraw.addEventListener(Event.ENTER_FRAME,function(e:Event){expand(e.target); },false,0,true);
    function expand(obj):void {
         obj.height+=3;
         obj.width+=3;
        How would I add a line here to remove that event?

    The more I look at that code the more I wonder about it.  First I questioned why the function was not called directly in the event listener like it normally would be (since it appears to be utilizing the event.target), then I wondered why an ENTER_FRAME event is being cancelled as soon as it seemingly starts. Is circDraw the obj of the function?  If so, why it isn't all that just reduced to being...
         circDraw.height+=3;
         circDraw.width+=3;
    with no listeners or functions involved.
    Maybe you have an explanation that I can't see from what is shown.

  • How to send the Event Listener arguments in AS3?

    In MXML
    <mx:Button click="clickHandler();"
    mouseDown="downHandler(event);" mouseOver="overHandler(btn);"
    mouseMove="moveHandler('RAJAN');"/>
    but AS3
    var btn:Button = new Button();
    btn.addEventListener(MouseEvent.CLICK, clickHandler, flase,
    0, true);
    only this kind of AS3 event only added, any other possibility
    to pass the arguments to handler function.
    please help.

    From that link:
    If you define an event listener inline (inside the MXML tag),
    you can add any number of parameters as long as the listener
    function's signature agrees with that number of parameters.
    If you add a listener with the addEventListener() method (in
    ActionScript), you cannot pass any additional parameters to the
    listener function, and that listener function can declare only a
    single argument, the Event object (or one of its subclasses).
    To pass additional parameters to listener functions defined
    in AS, you must define the parameters in the listener function and
    then call some other method passing it the additional parameters in
    the call from the listener.
    You can also define your own custom events, and then you are
    free to define what args your event listeners take, and access the
    data from the event object.

  • How to remove Action Event programatically

    Can i remove the Action Event programatically. Please provide the query for the same.

    Hi ,
    you can not remove Action Event programatically, although you can try to modify theexisting event using below code
    trashCanImageBean.setFireActionForSubmit ("delete",
    params, paramsWithBinds,false, false);
    so that the previous event may stop working , I never tried this , but an attempt can be done .
    Thanks
    Pratap

  • How to Remove Spacebar event from JFormattedTextField/JTextField

    Hello Friend,
    I have problem about JTextField.I want to remove or unregister Spacebar event from JTextField.
    I have used KeyMap,InputMap,also.
    So please help me

    Hello Friends,
    That is not ficiable for me.Actuall that JTextField is already use Document listener and focus listener and HexFormatter.
    In sort i am making a JFormattedTextField as Hex JTextField which will validate only 0-9 and a-f And A-F will be valide entry and remail it will ignore.
    I have made that one .but we require output like
    45 56 89 a4 59
    Here space will generate by programmer not user,he will enter only data....so i want remove space bar
    i have used this way but that is not working
    KeyMap space=txtBox.getKeymap()
    KeyStroke stroke=KeyStroke.getKeyStroke
    (KeyEvent.VK_SPACE,0);
    space.removeKeyStrokeBinding(stroke);
    but this not working

  • How to remove duplicate events in my ical icloud calendars?

    OS X 10.9.1
    I have too much duplicate events in my icloud calendars.
    How can I remove them automatically?
    Is there any App available that works?
    Thanks

    Thats a good tip Reggie.
    For anyone else reading this post, keep in mind that if you see "duplicates" with the MobileMe calendar it may mean you are seeing two separate copies of the same calendar.  Before spending time deleting individual events read this article: http://support.apple.com/kb/TS3505

  • How to remove upcoming events from iCal's day view

    Is there any way to remove the Upcoming Events list (on the left) from the Day view in iCal?
    They are distracting!

    Are these the components you need?
    I may have misunderstood.

  • Removing an event listener from buttons

    Hi.
    I´d like to know if it´s necessary to remove event listeners from buttons.
    I know it's good practice to remove event listeners when its use is over.
    But it´s necessary to remove event listeners for buttons as well?
    Thanks

    it's necessary if you want to ready your buttons for gc.

  • Cant remove enterframe event listener in control animation

    Hi
    I am trying to create a simple play, stop, rewind. fforward controller. I have the slideShow and the Control in the same time line.
    As the enterframe event is nested inside a function it will rewind but then none of the other buttons will work as I am not able to removeEventListener for the enterframe event. Thanks for looking. Regards
    stop();
    btnStop.addEventListener(MouseEvent.CLICK,StopSlideShow)
    btnPlay.addEventListener(MouseEvent.CLICK,PlaySlideShow)
    btnRewind.addEventListener(MouseEvent.CLICK,RewindSlideShow)
    function PlaySlideShow(e:MouseEvent):void
    play();
    function StopSlideShow(e:MouseEvent):void
    stop();
    function RewindSlideShow(e:MouseEvent):void
    addEventListener(Event.ENTER_FRAME,keeprewinding);
    function keeprewinding(e:Event):void
      prevFrame();
    if(currentFrame ==1)
    removeEventListener(Event.ENTER_FRAME,keeprewinding);

    stop();
    btnStop.addEventListener(MouseEvent.CLICK,StopSlideShow);
    btnPlay.addEventListener(MouseEvent.CLICK,PlaySlideShow);
    btnRewind.addEventListener(MouseEvent.CLICK,RewindSlideShow);
    function PlaySlideShow(e:MouseEvent):void
    removeEventListener(Event.ENTER_FRAME,keeprewinding);
    play();
    function StopSlideShow(e:MouseEvent):void
    removeEventListener(Event.ENTER_FRAME,keeprewinding);
    stop();
    function RewindSlideShow(e:MouseEvent):void
    addEventListener(Event.ENTER_FRAME,keeprewinding);
    function keeprewinding(e:Event):void
    if (currentFrame == 1)
      removeEventListener(Event.ENTER_FRAME,keeprewinding);
    prevFrame();

  • How to get any event occurs inside inline frame .

    Hi All,
    I have configured some url in af:inlineFrame component .
    This url is pointing to a webapplication which is hosted on different server .
    If i want to know all the activity what is happening insde inlineframe component which event i need to handle .
    I show all metadata of af:inlineframe component i dint find it handle any event .
    Please let me know how could it possible .
    Thanks ,
    Arun.

    Hi Sireesha,
    I have configured http://google.com as a source of inline frame component .
    Now google.com is rendered inside the inlineframe component .
    Whenever i will do some serach or click on the link appearing after searing something in google or someother activity .
    i want to intercept all the actions in my bean .
    Please let me know if above explanation is not clear .
    Thanks,
    Arun.

  • How to remove the title bar of a frame(java.awt.Frame)?

    How to get a frame without any TitleBar?

    setUndecorated(true);
    This also gets rid of the minimize, normalize, and close buttons from the upper right corner of the screen--so have a way to close and resize if you need it.
    btw: do you know how to bring up the API docs?

Maybe you are looking for

  • Problems with GMAIL

    Hello, I have been using BB Curve 9360 for quite some time and Gmail was working fine all these months.  I used it to access two accounts. I do not remember how I had installed it but the icon was the classic envelope with red borders.  From last sat

  • Explorer to JList Drag and Drop??

    Totally stuck on this one, need an example that allows a user to drag a file from Windows Explorer to a JList, thereby adding the filename to the JList.. looked all over and couldn�t manage to get it working, some demo code would be excellent.. A bit

  • HELP! Problem viewing Youtube videos.

    Hello, I am having problems viewing Youtube videos. Everything was great until the other day. I have not changed anything on my computer to create this problem. Diagnosis: when viewing videos straight from youtube.com with Safari, it loads and starts

  • Xquery concat / string-join / replace

    Hi, I am a newbie on Xquery. And I need some help on a problem I been having. My in data is three digit numbers (ex. "123" "321" "213" etc). And I need to separate this with a comma ",". The problem is how do I do this if the input is only one item?,

  • How can I sync two sources in address book 5.0?

    I love the new exchange support in Snow Leopard, this helps me keep my exchange contacts at work up to date. I would like to know how I can synchronize my exchange contacts with my local contacts which I have synchronized with GMail thanks to the new