5 Replies Latest reply on May 4, 2008 5:36 PM by kglad

    on clip event handlers not working

    pallwall
      HI,
      I'm having some trouble with my on clip event handlers. I'm learning action script from the macromedia action script manual and every time i write an on clip event handler, copying directly from the manual, I am getting an error message. Here's what it says as an examples....

      **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 3: Statement must appear within on/onClipEvent handler
      var star_array:Array = new Array();

      The statement is copied verbatim out of the text book so I'm confused as to what I am doing wrong. The on event handlers have been working but none of the on clip event handlers. Is there something I'm missing in my script or do I have to dissect the problem in my preferences? Really confused, any help would be much appreciated, thanks!
      paul
        • 1. Re: on clip event handlers not working
          kglad Adobe Community Professional & MVP
          that statement should not be attached to an object.

          to remedy, hightlight and right click that code and left click cut. then click on an empty part of the stage, right click on the actions panel and click paste. retest.
          • 2. Re: on clip event handlers not working
            Paul_Leri
            I tried not attaching it to an object but i continue getting the error message. here is my full code and below it are the error messages. Is there something wrong with the flash i'm using, the on Clip handlers aren't working in multiple files...

            import mx.transitions.Tween;

            var star_array:Array = new Array();
            for (var i:Number = 0; i < 20; i++) {
            makeStar();
            }
            function makeStar():Void {
            var depth:Number = this.getNextHighestDepth();
            var star_mc:MovieClip = this.attachmovie("star_id","star" + depth, depth
            star_mc._rotation += 5;
            }
            star_mc._y = Math.round(Math.random() * Stage.height - star_mc._height / 2);
            var star_tween:Tween = new Tween(star_mc, "_x", null, 0, Stage.width, (Math.random() * 5) + 5, true);
            star_tween.onMotionFinished = function():Void {
            star_tween.yoyo();
            };
            star_array.push(star_mc);
            }
            var mouseListener:Object = new Object();
            mouseListener.onMouseDown = function():Void {
            var star_mc:MovieClip;
            for (var i:Number = 0; i < star_array.length; i++) {
            star_mc = star_array ;
            star_mc.cacheAsBitmap = !star_mc.cacheAsBitmap;
            }
            }
            Mouse.addListener(mouseListener);

            **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 1: Statement must appear within on/onClipEvent handler
            import mx.transitions.Tween;

            **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 3: Statement must appear within on/onClipEvent handler
            var star_array:Array = new Array();

            **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 4: Statement must appear within on/onClipEvent handler
            for (var i:Number = 0; i < 20; i++) {

            **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 10: ')' or ',' expected
            star_mc._rotation += 5;

            **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 7: Statement must appear within on/onClipEvent handler
            function makeStar():Void {

            **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 12: Statement must appear within on/onClipEvent handler
            star_mc._y = Math.round(Math.random() * Stage.height - star_mc._height / 2);

            **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 13: Statement must appear within on/onClipEvent handler
            var star_tween:Tween = new Tween(star_mc, "_x", null, 0, Stage.width, (Math.random() * 5) + 5, true);

            **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 14: Statement must appear within on/onClipEvent handler
            star_tween.onMotionFinished = function():Void {

            **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 17: Statement must appear within on/onClipEvent handler
            star_array.push(star_mc);

            **Error** Scene=Scene 1, layer=Layer 1, frame=1:Line 18: Unexpected '}' encountered
            }

            Total ActionScript Errors: 10 Reported Errors: 10



            • 3. Re: on clip event handlers not working
              clbeech Level 3
              as kg is saying - this code belongs on a 'frame' - not attached to an 'object' - you must select a frame on the timeline (we usually use a new layer called actions) - and with the 'frame' selected open the actions panel and place the code there.

              also the 'cacheAsBitmap' property requires a 'boolean' (true) assignment.
              • 4. Re: on clip event handlers not working
                Paul_Leri Level 1
                that was a great help! thanks so much both of you!
                p
                • 5. Re: on clip event handlers not working
                  kglad Adobe Community Professional & MVP
                  you're welcome.