Stopping my object [newb]

I have an ball that moves across the screen and it works fine.
Now I am trying to add code that will stop it when I click the mouse button.
When I run the movie my clicks do nothing.
Can someone look at my code and tell me where I am going wrong?
Thank you.
<code>
package {
          import flash.display.MovieClip;
          import flash.events.Event;
          import flash.events.MouseEvent;
          public class Soccer extends MovieClip {
                    public function Soccer(){
                              this.addEventListener(Event.ENTER_FRAME,update);
                              this.addEventListener(MouseEvent.CLICK, clickHandler);
                    private function updatePosition():void {
                              this.x++;
                              this.y++
                    private function update(e:Event): void {
                              this.updatePosition();
                    public function clickHandler(evt:MouseEvent): void {
                              this.stop();
          }//close constructor
}//close package
</code>

A couple of suggestions/tricks.
1. Class constructor should have as little logic as possible. Eventually you will find that this is not only a coding style advice but something that has positive practical implications. In general the more specialized functions are, the more scalable solution you deal with.
2. It does feel intuitive to use stop() methods to seize object movement. However, MovieClip documentation states that "Stops the playhead in the movie clip." Note that in your class you did not do anything move playhead.
Adding ENTER_FRAME listener has nothing to do with the generic MovieClip playhead. ENTER_FRAME just makes code to execute before screen is refreshed.In other words, stop() does not remove ENTER_FRAME event listeners automatically.
You can look at this from a different perspective. At this point it is clear that method stop() does not have enough functionality to accommodate your objectives. But it can be changed. Subclass can override any public API entities in AS3 (polymorphism).
Class below demonstrates that. It kills two birds with one stone - preserves native MovieClip stop() method functionality and adds logic that implements objectives of your Soccer
package
          import flash.display.MovieClip;
          import flash.events.Event;
          import flash.events.MouseEvent;
          public class Soccer extends MovieClip
                    public function Soccer()
                              init();
                    private function init():void
                              addEventListener(Event.ENTER_FRAME, update);
                              addEventListener(MouseEvent.CLICK, clickHandler);
                    private function update(e:Event):void
                              x++;
                              y++;
                    public function clickHandler(e:MouseEvent):void
                              stop();
                    override public function stop():void
                              super.stop();
                              removeEventListener(Event.ENTER_FRAME, update);

Similar Messages

  • Using ncAction to Start & Stop CAN objects

    Hello,
    I have to start and stop CAN Objects and I have unexpected results : if
    I set NC_ATTR_START_ON_OPEN to NC_TRUE in the interface configuration,
    everything works properly. Then if I set NC_ATTR_START_ON_OPEN to
    NC_FALSE, ncAction function does not work properly.
    I'm using NI-CAN v2.3.
    Here is a sample of my code.
    Any suggestion about that problem ?
    Attachments:
    CAN_ncAction.c ‏5 KB

    Hi JCX,
    I can reproduce your Problem. It seems that there is something wrong with the handles. We work to get it fixed, but it can take a little while.
    For the moment the workaround is to start the second Object (ncAction) before you try to Stop it. The new Start will fix  a kind of a handle problem, so you should be able to Stop the Object then.
    It should look like this then:
     // Start the network interface and CAN objects
      NiCANErrChkMsgPopup(ncAction (PortHandle, NC_OP_START, 0));  
      // Stop the Second Frame
      NiCANErrChkMsgPopup(ncAction (HdleSTD301, NC_OP_STOP, 0)); 
    // Start the  CAN object
      NiCANErrChkMsgPopup(ncAction (HdleSTD1495, NC_OP_START, 0));  
      // Stop the First Frame
      NiCANErrChkMsgPopup(ncAction (HdleSTD1495, NC_OP_STOP, 0));
    because the Stop cleanes the message queues, you have to write a new message to the write queue before any restart.
    hope that helps
    DirkW

  • WebDynpro app stopped working (Object not found in lookup of JPA_DEFAULT)

    Hi,
    my scenario is as as described in my posting (java.lang.IllegalArgumentException: model object must not be null). after i got everything up and working it suddenly stopped.
    the wedynpro project is implicitly stopped, beacuse earecipe could not start, reason:
    [code]
    Error occurred on server 15129750 during startApp demo.sap.com/earecipe : com.sap.engine.services.orpersistence.container.deploy.ActionException: Clusterwide exception: com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Object not found in lookup of JPA_DEFAULT.
    at com.sap.engine.services.jndi.implserver.ServerContextImpl.lookup(ServerContextImpl.java:582)
    at... [see details]
    Error occurred on server 15129750 during startApp demo.sap.com/earecipe : com.sap.engine.services.orpersistence.container.deploy.ActionException: Clusterwide exception: com.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Object not found in lookup of JPA_DEFAULT.
    at com.sap.engine.services.jndi.implserver.ServerContextImpl.lookup(ServerContextImpl.java:582)
    at com.sap.engine.services.jndi.implclient.ClientContext.lookup(ClientContext.java:343)
    at com.sap.engine.services.jndi.implclient.ClientContext.lookup(ClientContext.java:637)
    at javax.naming.InitialContext.lookup(InitialContext.java:351)
    at javax.naming.InitialContext.lookup(InitialContext.java:351)
    at com.sap.engine.services.orpersistence.container.deploy.impl.ComplexModuleCreator.initDataSources(ComplexModuleCreator.java:277)
    at com.sap.engine.services.orpersistence.container.deploy.impl.ComplexModuleCreator.initRuntimeModels(ComplexModuleCreator.java:246)
    at com.sap.engine.services.orpersistence.container.deploy.impl.ComplexModuleCreator.createModule(ComplexModuleCreator.java:151)
    at com.sap.engine.services.orpersistence.container.deploy.impl.ComplexModuleCreator.execute(ComplexModuleCreator.java:81)
    at com.sap.engine.services.orpersistence.container.deploy.impl.ComplexActionAdapter.execute(ComplexActionAdapter.java:34)
    at com.sap.engine.services.orpersistence.container.deploy.impl.ApplicationCreator.execute(ApplicationCreator.java:74)
    at com.sap.engine.services.orpersistence.container.deploy.impl.PersistenceContainer.prepareStart(PersistenceContainer.java:187)
    at com.sap.engine.services.deploy.server.application.StartTransaction.prepareCommon(StartTransaction.java:211)
    at com.sap.engine.services.deploy.server.application.StartTransaction.prepare(StartTransaction.java:171)
    at com.sap.engine.services.deploy.server.application.ApplicationTransaction.makeAllPhasesOnOneServer(ApplicationTransaction.java:393)
    at com.sap.engine.services.deploy.server.application.ParallelAdapter.makeAllPhasesImpl(ParallelAdapter.java:480)
    at com.sap.engine.services.deploy.server.application.StartTransaction.makeAllPhasesImpl(StartTransaction.java:537)
    at com.sap.engine.services.deploy.server.application.ParallelAdapter.runMe(ParallelAdapter.java:149)
    at com.sap.engine.services.deploy.server.application.ParallelAdapter$2.run(ParallelAdapter.java:350)
    at com.sap.engine.frame.core.thread.Task.run(Task.java:73)
    at com.sap.engine.core.thread.impl5.SingleThread.execute(SingleThread.java:130)
    at com.sap.engine.core.thread.impl5.SingleThread.run(SingleThread.java:226)
    [/code]
    whats that supposed to mean, i'm not using any JPA functionality at the moment.
    regards,
        christian

    Hi,
    you have to define a datasource alias for your db (in "Application Resources" in SAP Netweaver Administrator) or use an existing one and add it as a "jta-data-source" child for your corresponding persistence unit within your persistence.xml
    regards,
      christian

  • First Website. How do I stop an object in horizontal motion?

    I have no web design experience at all, and  I've searched all over, but perhaps I don't know the correct lingo. I want to apply a horizontal scrolling motion to an object, but I only want it to move about an inch or so to the right and then stop. I can only seem to get it to keep moving off the page. It's part of a pinned menu bar, as soon as you start scrolling down, I want the menu buttons to separate from the middle to make room for the logo that will drop in the center of the bar from the top.

    I've tried that. It just keeps going off the page as I scroll down. Maybe I'm not doing something right? It seems like there should be something else I need to do to tell the object where and when to stop.
    Perhaps this image will better convey what I'm trying to do. The menu items are together at the top of the screen, as soon as you scroll down they should separate slightly from the middle and stop, making room for the logo.

  • Stop Web Object audio on screen exit - Cap 7

    I have a series of slides, each with one Web Object. Each is a link to an HTML page with an MP4/player. If I want to go to the next slide while the movie is playing, the audio does not stop on exit.  I can't do an action on Exit as the audio isn't from an Advanced Action but from the Web Object. Am I missing something obvious here?
    Thanks in advance...

    The JavaScript API for Captivate is different for SWF vs. HTML5 output.  Both are a mess and have inconssistencies... and there is no documentation.  I'm hoping the Adobe Captivate Dev Team will address this for Cp 8.  For SWF output, you can look here:
    http://captivatedev.com/2012/07/01/adobe-captivate-6-the-javascript-api/
    And here:
    http://blogs.adobe.com/captivate/2010/12/captivate-swf-events.html
    The HTML5 API is much more versatile where you can subscribe to the events mentioned in the last link.  I'd recommend poking around with Chrome's dev tools to see what's available in HTML5 land.

  • Adding stop points; complete newbie question

    I like to download lectures from the internet. they come in as one long file. If I take them into Garageband can I add stop points every 10 minutes or so? I want to be able to make a CD with those stop points so it is easier to go back and forth to different points in the lecture.
    Richard

    you can add markers by showing the podcast track, then when you burn it to CD with GB you'll be able to jump to the different points.
    (for more info search for "marker" in GB's help")

  • Problem translating object, newbie question.

    I'm new to java3D, and I'm having problems translating an object. Here's the thing:
    I have two different sets of dimensions for creating 2 boxes.
    x1 = 100
    y 1= 0
    z 1= 100.
    And
    x 2= 50
    y 2= 50
    z 2= 50.
    I divide everything by the maximum dimension (100). So:
    x 2= 0.5 x1 = 1
    y 2= 0.5 y 1= 0
    z 2= 0.5 z 1= 1
    So, now I have a box with dimensions (1, 0, 1) = (x1, y1 z1)
    And the other one has (0.5, 0.5, 0.5) = (x2, y2, z2)
    Here is what I want to do:
    I want to put the second box on top of the first one. In order to do this I create a Transform3D object and call the set method with: new Vector3f(0, (x1+x2) /2, 0)
    I thought that would work, but I end up seeing the second box half way or being on top of the first one.
    Thanks for the help

    I solved it, was kind of confused on which point of the box I was translating...

  • Selection tool won't stop dragging objects when they are clicked on

    In CS6 I keep clicking on objects hoping to be able to edit them but they keep moving ruining the whole composition. I have uninstalled and reinstalled, used a different mouse and it still keeps doing this.

    Not sure if this is the one you are talking about that deals with a similar problem http://forums.adobe.com/message/5122845#5122845.

  • Stop HTML object from moving

    Hello,
    I have added several HTML objects to a Muse website page that I am using to embed YouTube videos. The boxes line up fine in Design mode however when I go to Preview mode the objects bunch up together then separate as I scroll down the page. How do I get the obects to stay where I have placed them on the page?
    Example Object HTML:
    <object width="560" height="315"><param name="movie" value="//www.youtube-nocookie.com/v/zQNcPJfWG5U?hl=en_US&amp;version=3&amp;rel=0"></param ><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="//www.youtube-nocookie.com/v/zQNcPJfWG5U?hl=en_US&amp;version=3&amp;rel=0" type="application/x-shockwave-flash" width="560" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object>

    Can you provide a link to the site so we can see it? Sounds like you might have scroll motion set on some elements.

  • Business Objects newbie... how to install???

    I downloaded the free trial of SAP BusinessObjects Edge BI 3.1.   However I am a little confused on the following subjects:
    1) What are the hardware requirements
    2) What OS will it run under
    3) What database/web server requirements are
    4) What are the exact steps necessary to install the product?
    I tried reading the Installation Guide.   However all it does is refer me to Articles  
    I don't see anything there that is particular to Edge BI 3.1; not at least that I can see.
    Any help would be appreciated!

    Hi,
    please go to [http://service.sap.com/bosap-support]. YOu will find a link to the supported platforms documents there.
    Are you trying to install on windows or on unix?
    Regards,
    Stratos

  • DW 4 - can I stop it from opening the objects window by default

    I've used Dreamwaver 4 for years, and have closed the objects
    windows a few hundred thousand times because it opens by default
    every time I open an html file. Is there any way to set the default
    so that the objects window does NOT open automatically. The
    properties window also opens by default, but that is fine. Any
    suggestions on how to stop the object window from opening every
    time, or even if it can be done...

    Pure guesswork, but when I had problems with iTunes launching again and again, the reason were my external speakers. I simply had to unplug the speakers  from the line-out socket, and iTunes stopped launching on its own.

  • Photoshop 7 - object handles no longer showing

    Photoshop 7 has suddenly stopped showing object handles, so I am unable to resize or transform a portion of an image that I have selected. I can find no instructions as to how I can get the handles to show again. Can anyone help?

    Invoking the Free Transform function (CTRL + T, or from the Edit menu) will cause the Transform Bounding Box to appear.
    If you want to see the TBB all the time, select your Move Tool. In the Options Bar check the box labeled "Show Transform Controls."

  • Is it necessary to null any unused objects?

    Hi folks,
    I have heard people said to null and not to null the unused objects both. To be honest, I really notice nulling the objects will help to reclaim the memory from the unused objects. Please tell me if I am doing it wrong, thanks!
    Billy

    evebill8 wrote:
    I have heard people said to null and not to null the unused objects both. 'objects' are not set to 'null'. References to objects can be set to 'null' . When a reference goes out of scope then the referenced object becomes eligible for garbage collection if there are no other references to it.
    References should be declared in the shortest scope possible that way they exist for the shortest time possible and cannot be responsible for stopping an object being garbage collected.
    To be honest, I really notice nulling the objects will help to reclaim the memory from the unused objects. Please tell me if I am doing it wrong, thanks!If you "notice nulling the objects will help to reclaim the memory from the unused objects" then the chances are you have declared the references in too wide a scope. How do you know that it makes a difference in your programs? What measurements have you made?
    There are some situations when you need to set references to null but they are few and far between. Just make the scope of a reference as small as possible.

  • Currently not available "Stop" or "Continue"

    I'm getting 6 error windows when I start Photoshop CS4.
    the command "make" is not currently available, "continue" or "stop"
    the command "feather" is not currently available, "continue" or "stop"
    the command "layer via copy" is not currently available, "continue" or "stop"
    the object "layer" is not currently available, "continue" or "stop"
    the object "fill" is not currently available, "continue" or "stop"
    the object "current layer" is not currently available, "continue" or "stop"
    Why?  Anyone know how to root out the culprit?
    Thanks in advance

    Seems like Photoshop is trying to run an action on starting the application
    try   file > scripts > scripts event manager   is it enabled to run an action on startup?

  • NFS for newbie

    Hi all!
    I have just bought a MacMini with OSX Server, and I started trying to configure NFS! However, nothing seems to work!
    What did I do? I connected with the Server Admin app to my MacMini, and enabled NFS. When I connect to it with my iMac, Finder says that the server does not respond. This is what I find in Server Admin:
    Under the server name I find "NFS", and clicking on the green light I can see:
    NFS: Running
    nfsd: Stopped
    portmap: Stopped
    rpc.lockd: Stopped
    rpc.statd: Stopped
    From my newbie point of view, I don't think it's a great thing that all services except NFS are stopped. Do I need to start them, and how? I don't see portmap in Settings > Services.
    Anyway, under "File Sharing" in Server Admin app, I have a volume that I can "Unshare", so I think this is OK.
    Can anyone explain me how to enable NFS? I thought it would be easier
    Another probably silly question: can I enable only some users to connect to NFS?
    Thanks & Cheers!!

    Hi! I played around and I found that I needed to set up a mount point, and next explicitly enable NFS. Now it's all working! Of course, ACLs too!

Maybe you are looking for