16 Replies Latest reply on Aug 15, 2007 1:55 PM by SymTsb

    AS 3.0 nightmare

    C-Rock Level 2
      Okay, AS 3.0 needs a book/manual where you can view the changes from old practices to new.

      I used to create variables on my main timeline and access them through this

      trace(_root.thisNum);

      on the root timeline I would have a variables section set aside like:

      thisNum:Number = 5;


      So in a burried clip or any function I could say:

      trace(_root.thisNum) // output would be 5

      How in the heck do you do this in 3.0.

      I've tried everything. seems like stage.root.thisNum should work. or this.parent.thisNum.

      Neither do....
        • 1. Re: AS 3.0 nightmare
          SymTsb Level 2
          Do a search in the AS3 help for AS2.0 Migration...... That will give you more insight into how to deal with the changes from AS2 to AS3. As for the other problem...

          var thisNum:Number = 5;

          function displayNumber( ):void {
          trace(thisNum);
          }

          displayNumber();

          That should trace out 5.

          AS3 handles scope a lot better than it did in the past. The only reason I have to use root or parent any more is if I'm using the Loader class.
          • 2. Re: AS 3.0 nightmare
            C-Rock Level 2
            it works fine on the main timeline. i'm talking about if you are inside a movie clip and you need to acces the thisNum variable. thie movie clip name is mainSection and it resides on the mainTimeline.

            you could have before said:

            trace(_root.thisNum) or trace(this._parent.thisNum);

            in AS 3.0 //
            trace(thisNum); doesn't work from places outside the main timeline.
            • 3. AS 3.0 nightmare
              SymTsb Level 2
              Try this from inside the movieclip and tell me what you get C-Rock

              function getRootNumber( ):void {
              trace((this as MovieClip).parent.thisNum);
              }

              getRootNumber();

              Also keep in mind that _root and _parent have been replaced by root and parent respectively in AS3.
              • 4. Re: AS 3.0 nightmare
                C-Rock Level 2
                trace(this.mapSection.parent.thisNum);
                trace(mapSection.parent.thisNum);
                trace((this as mapSection).parent.thisNum);

                None work by themselves inside the function you gave.
                • 5. Re: AS 3.0 nightmare
                  SymTsb Level 2
                  use the code exactly as I gave it to you. (this as MovieClip) is simply an enforced type cast of your mapSection timeline to MovieClip so that I knew 100% that accessing the parent property would not result in a null object reference. Try the code as it is in my post and tell me what you get.
                  • 6. Re: AS 3.0 nightmare
                    C-Rock Level 2
                    this error

                    1119: Access of possibly undefined property thisNum through a reference with static type flash.display:DisplayObjectContainer.
                    • 7. Re: AS 3.0 nightmare
                      SymTsb Level 2
                      Let me go pull my Laptop down here and I'll build the example file. 10 minutes or so.....
                      • 8. Re: AS 3.0 nightmare
                        C-Rock Level 2
                        okay, geez, i feel like an idiot, i'm kinda of an expert at a 2.0. i thought i was doing everything correct, but accessing variable throughout the timelines and from classes is just a nightmare.

                        by the way no migration docs can be found anywhere? not even in my cs web design suite package of extra discs...

                        thanks for your help
                        • 9. Re: AS 3.0 nightmare
                          SymTsb Level 2
                          Here's the full code example...

                          • 10. Re: AS 3.0 nightmare
                            SymTsb Level 2
                            Flash CS3 - > Help

                            Set Dictionary File to ActionScript 3.0 and search for just the word Migration. ActionScript 2.0 Migration page should be the only result. This page just tells you want changed and what was removed but if the function was moved etc, it tells you what you need to import and you can follow through with a link that will lead you directly to the function or class along with it's code examples.

                            AS3 is a big change from AS2 unless you were one of the people who did almost everything from external classes etc. Granted, the display list is completely new and takes getting used to but it is so much nicer programatically than AS1 or 2 ever were.
                            • 11. Re: AS 3.0 nightmare
                              C-Rock Level 2
                              what the hell? why? and how do i access the same variable from a loaded class?
                              • 12. Re: AS 3.0 nightmare
                                C-Rock Level 2
                                okay, i saw that but it doesn't help much really. i need a side by side and an explaination of how to do the things i used to do. my advanced apps i used to design will take forever in as 3 if i just don't get a book and learn it. thanks for all your help.
                                • 13. Re: AS 3.0 nightmare
                                  SymTsb Level 2
                                  if the variable is in the root clip, and the class object is being instantiated with new ClassName(), it's pretty much exactly the same....

                                  // a private or public function inside your class file
                                  // private function only accessible to other members of the class
                                  // another function inside the class will need to call this function
                                  private function getRootNumber():void{
                                  trace( "INSIDE getRootNumber: " + (root as MovieClip).thisNum );
                                  }

                                  // if it's public you can just call the function yourself
                                  private function getRootNumber():void{
                                  trace( "INSIDE getRootNumber: " + (root as MovieClip).thisNum );
                                  }

                                  then from the timeilne where the className exists...
                                  className.getRootNumber();

                                  The reason you need to use (root as MovieClip) is so that Flash will allow you to access members, variables and other errata as you would for any MovieClip you create in the environment. All I did in essence was tell Flash that I want to access the root DisplayObjectContainer as a MovieClip and then its thisNum property which is all the variable thisNum is as far as the compiler is concerned. Does that make sense?
                                  • 14. Re: AS 3.0 nightmare
                                    SymTsb Level 2
                                    quote:

                                    Originally posted by: C-Rock
                                    okay, i saw that but it doesn't help much really. i need a side by side and an explaination of how to do the things i used to do. my advanced apps i used to design will take forever in as 3 if i just don't get a book and learn it. thanks for all your help.


                                    I'm facing the same issues as you are. It took me 4 hours to rework my basic preloader script when I first started playing with AS3 and now some of my other classes for creating dynamic windows, thumbnail based image galleries, XML data loaders..... a freaking nightmare for me to change over. It's taken me months to convert code over from AS3 and my struggle still continues as we speak. Feel free to add me to your address book C-Rock. I'm always available via e-mail. mike@sd-dezign.com

                                    • 15. Re: AS 3.0 nightmare
                                      C-Rock Level 2
                                      thanks a lot for you help, again. it makes much more sense now. i'll add you to my address book. i'm carey@richardson-graphics.com

                                      carey
                                      • 16. Re: AS 3.0 nightmare
                                        SymTsb Level 2
                                        Carey, I've added you to my a-book as well. Been a pleasure and I'm glad I was able to help.