9 Replies Latest reply on Jun 30, 2006 7:52 PM by injpix

    events in classes

      I'm working on a projector class for displaying images as a slide show. I've been getting errors like as follows:

      **Error** D:\jjesteban.com\src\flash\SlideScroller\Projector.as: Line 98: This statement is not permitted in a class definition.

      Is it not possible to code events in a class definition.
        • 1. Re: events in classes
          Peter Lorent Level 2
          Maybe show just a few more lines of code... this is not enough info to give a meaningful answer.
          • 2. Re: events in classes
            injpix Level 3
            That line of code is probably not inside the class method from the type of error you are receiving.

            private function myEvent()
            this.onLoadComplete = function()

            But that does not necessary means your problem is fixed. Yeah we need more code.
            • 3. Re: events in classes
              Jim_Esteban Level 1
              I got passed the intial errors by putting all of the events inside of the constructor. I've linked an empty movie clip to this class and when I run the program the onEnterFrame seems to work okay until I run initialize in the main time. The first slide loads okay but then it doesn't seem to get the onenterframe event anymore.
              Here's the entire class.
              • 4. Re: events in classes
                injpix Level 3
                I haven’t fully looked at your code except the onEnterFrame handler that is in your class. You have;


                The key word ‘this’ is referring to the class not necessary the timeline unless you have the linkage for this MovieClip to receive myClass. This can be done by right-clicking on the symbol tab to ‘Linkage’ and the field that says ‘AS 2.0 class’ in the popup is where the name of the class would go. Also if you are creating an instance of this class on the _root the onEnterFrame will not work as you have it. You need to target the timeline. So I always target the timeline in my constructor as below;
                • 5. Re: events in classes
                  Peter Lorent Level 2
                  That's a few more lines of code...

                  >>The first slide loads okay but then it doesn't seem to get the onenterframe event anymore.
                  Resulting in what problem? Scroller won't work? Next slides won't load? Won't autoplay? Please try to elaborate on the exact problem so we don't have to read the whole (uncommented) code.
                  • 6. Re: events in classes
                    Jim_Esteban Level 1
                    I've had the AS 2.0 Linkage set to the class name "Projector" from the beginning.
                    //in the FLA
                    mC = new myClass(this);

                    This instance name of the MovieClip which is linked to the Projector class in Projector1_mc. Should the above line of code go there or in the root.

                    //in the AS- myClass.as
                    class myClass extends MovieClip
                    private var target_mc:MovieClip;

                    public function myClass(t)
                    Where does t come from?
                    this.target_mc = t;

                    this.target_mc.onEnterFrame = function()
                    trace("hitting the frame");

                    Thanks for your help. I have given up a couple of times out of frustration, but I keep on coming back to it. This morning I was reading the documentation and It say's:
                    You can define the function on the timeline or in a class file that extends the MovieClip class
                    So I should be able to do this.
                    • 7. Re: events in classes
                      injpix Level 3
                      If you have the Linkage set up to the class you created then there is no need to create a new instance of that class using the following code;

                      mC = new myClass(this);

                      If that movieclip that has your Projector class wired to it thru the linkage is on stage you should be ok. Is it? Or is it dynamically attached to the stage? If not you can attach it to the stage, attachMovie().

                      “Where did you t come from”

                      If you don’t have the class wired to the symbol via Linkage then we would have to go about this task by creating an instance…

                      mC = new myClass(this);

                      This creates an instance of your class that passes the only parameter to the constructor function (the function that has the same name of the class). This function is automatically invoked and must be public when an instance is created, which we named, “mC”. ‘this’ is referring to the timeline, which is a MovieClip datatype. ‘this.target_mc’ that is in the class inherits the scope from the timeline thru ‘t’. We then use ‘this.target_mc’ to reference the timeline. Does that help? I hope I am not pointing out the obvious to you.
                      • 8. Re: events in classes
                        Jim_Esteban Level 1
                        I simplified some of the code and I attached the output screen. I'm using the onEnterFrame of projector1_mc you can see it running in the output then I push a button on the scroller and it goes through Intialize and in a short time it loads the image and after that the projector1_mc onEnterFrame stops running. Don't know why.

                        You can see the current state of the program running at:
                        • 9. Re: events in classes
                          injpix Level 3
                          So what exactly is your question now or do you have one?