6 Replies Latest reply on Jun 1, 2006 1:00 PM by TimSymons

    Runtime components problem

      I've created a custom class in which I create an instance of the datagrid component.

      Unless I change " this.createClassObject[...]" to " _root.createClassObject[...]", the component fails to show in the test movie.
      Of course, I don't want to use _root. I've tried using "this._parent" to no avail. Please help. I'm using WinXP and Flash8Pro.

        • 1. Re: Runtime components problem
          to be honest I don't really understand the problem (I don't use the version 2 components if I can avoid) but a quick glance at the docs would suggest that you also have to import

          import mx.data.binding.*;

          But that is not more than a wild guess and maybe a very uneducated one, as I don't really see why it would work with _root if I'm right...)
          • 2. Re: Runtime components problem
            mm21h Level 1
            Wouldn't work with _root, exactly. That's why I'm stumped! lol

            If I take the "this.createClassObject(DataGrid, 'dg', this.getNextHighestDepth());" line and put it in its own FLA, it works like a charm. If I use _root in the class, it works fine.

            That's why, after looking through the Flash Help, I can't seem to figure this thing out.
            • 3. Re: Runtime components problem
              mm21h Level 1
              • 4. Runtime components problem
                TimSymons Level 1
                If you are attaching the class to a MovieClip, like you are creating your own component, then your code works just fine. If, however, you are initializing the class like this:

                var myVar:SpmUI = new SpmUI();

                Then it will not work as written because the keyword "this" has no physical reference. If you want to use this method you will have to pass it a reference to a movieClip. For example, if you added a private member like:

                private var __target:MovieClip;

                then changed your Constructor to read as:

                public function SpmUI(target:MovieClip) {
                __target = target;

                Then in your init() function change the line that initiates the DataGrid from:

                this.createClassObject(DataGrid, 'dg', this.getNextHighestDepth());


                __target.createClassObject(DataGrid, 'dg', this.getNextHighestDepth());

                Then it will work.

                • 5. Runtime components problem
                  mm21h Level 1
                  Thanks for taking the time Tim!

                  Currently, I have a main.fla which only contains "new SpmUI();".

                  Which method would be the best practice?

                  EDIT: I've just tried what you suggested. It works fine. More importantly, I understand why it works and why it didn't before!!
                  One thing you didn't mention, that you must have thought I already knew, was to pass "this" as a parameter when calling "new SpmUI( this);"

                  Also, why should I use double underscores? Is this a standard to create custom levels?

                  Is this the best way of using classes?
                  • 6. Re: Runtime components problem
                    TimSymons Level 1
                    There is a large discussion on which way to use classes is the best. The end result is that which ever way makes the most sense for you and your program is the method you should use.

                    Sorry about forgetting the (this) part, that was kind of key, wasn't it? :-)

                    I used the double underscore because "_target" is a property and I like to completely distinguish my private variables from any built-in properties or other variables used to receive parameters from functions. Also, if I just used "target" as my private variable then given my function parameter name the code would have looked like:

                    target = target;

                    That may or may not have worked. Even if it did, it would be confusing to read when trying to debug.

                    My practice on attaching and not attaching classes to movieclips depends on what the class will have to control. If I have a lot of elements that will be controlled with the class, I find it easier to place them in the movbieclip during authoring rather than having to generate them through code. Also, if I draw a lot of custom graphics then I will also attached the class to the movieclip because I am not that good at using the DrawAPI.