38 Replies Latest reply on Jul 13, 2006 7:29 AM by Peter Lorent

    V2 Components

    FlashAmit Level 1
      i have been using the template downloaded from adobe but I receive following error

      **Error** C:\work\Incubis\developement\Building.as: Line 43: There is no property with the name 'bB'.
      bB = createObject("bBase", "bB", this.getNextHighestDepth());

      **Error** C:\work\Incubis\developement\Building.as: Line 44: There is no property with the name 'bB'.
      bB._x = 0;

      **Error** C:\work\Incubis\developement\Building.as: Line 45: There is no property with the name 'bB'.
      bB._y = 0;

      Total ActionScript Errors: 3 Reported Errors: 3

      title: undefined
      files are here BuildingComponents.zip
        • 1. V2 Components
          Peter Lorent Level 2
          The error indicates that you don't have declared the property bB in the class definition. Since you're most likely to use a MovieClip, you should declare:
          private var bB:MovieClip;
          or use the bBase property that is already declared in the class definition:
          bBase=createObject("bBase", "bB", this.getNextHighestDepth());
          or use a local var... without declaring bB as an instance property:
          var bB:MovieClip=createObject("bBase", "bB", this.getNextHighestDepth());
          However, this will bring up the next error on createObject() which is an undefined method. I think you mean createClassObject() which most likely must be attachMovie();
          • 2. Re: V2 Components
            FlashAmit Level 1
            Thanks for your help. This is solved by replacing with 'attachMovie'.

            Now need to make a loop and attach a number of Movie Clips. The number of instances will be passed as argument to the class. I am not getting how to start. Where and how to declare instances.
            i thought of
            for (var i = 1; i<10; i++) {
            this["floor"+i] = attachMovie("bFloor", "floor"+i, this.getNextHighestDepth());
            this["floor"+i]._x = xCor;
            this["floor"+i]._y = yCor-bB._height-gFloor._height-((i-1)*floorHeight);
            }

            but Nothing was declared earlier.
            Please suggest....
            • 3. Re: V2 Components
              Peter Lorent Level 2
              >>The number of instances will be passed as argument to the class
              Then you should start with declaring an inspectable:
              [Inspectable] private var floors:Number;
              so the number of floors will appear in the component definition dialog box as a component parameter.
              Then you can use the number in the loop (just as an example)
              public function createBuilding():Void {
              for(var i=0;i<floors;i++){
              bBase = attachMovie("bBase", "bB"+i, this.getNextHighestDepth());
              bBase._x = xCor;
              bBase._y = yCor-bB._height-gFloor._height-((i-1)*floorHeight);
              size();
              }
              }
              • 4. Re: V2 Components
                FlashAmit Level 1
                This works perfectly.

                Now i have made the floor as animated. So as it plays to increse its height.
                i want as its height increses the floors above it shift simultaneously.

                I tried this

                bBase.onRollOver = function() {
                trace(this);
                this.gotoAndPlay(2);
                for (var j = int(this._name.charAt(this._name.length)); j<floors; j++) {
                this["bB"+j]._y -= 12;
                }
                };
                };

                Please help. Latest Files are here.
                • 5. Re: V2 Components
                  Peter Lorent Level 2
                  When you create the floors save references in an array. In the onRollOver delete the name of the 'current' mc from the array and call a function to animate the other floors, passing the array with the references to that function. In the function you can use an onEnterFrame or use the Tween Class to move the floors.
                  • 6. Re: V2 Components
                    FlashAmit Level 1
                    I added the floors var. Now shen I trace it says 'undefined'.

                    Whats wrong here....





                    • 7. Re: V2 Components
                      Peter Lorent Level 2
                      fName.push(bBase);
                      attachMovie() returns a reference.
                      • 8. Re: V2 Components
                        FlashAmit Level 1
                        on Rollover to the 'bFloor' MCs
                        trace(this._name+">"+(int(this._name.charAt(this._name.length-1))+1)+">"+floors);
                        returns

                        bB1>2>undefined
                        I have tried this.floors. Even then result is same
                        • 9. Re: V2 Components
                          Peter Lorent Level 2
                          floors is out of scope there. Use a local reference to the class in createBuilding() to access floors.
                          • 10. Re: V2 Components
                            FlashAmit Level 1
                            Please see for loop has access to 'floors' but not available in the 'trace'

                            public function createBuilding():Void {
                            // code.....
                            for (var i = 1; i<=floors; i++) {
                            bBase = attachMovie("bFloor", "bB"+i, this.getNextHighestDepth());
                            // code.....
                            bBase.onLoad = function() {
                            trace(floors);
                            }
                            }
                            • 11. Re: V2 Components
                              Peter Lorent Level 2
                              Because the trace is in the onRollOver floors is out of scope. Try the local reference.
                              • 12. Re: V2 Components
                                Peter Lorent Level 2
                                public function createBuilding():Void {
                                var thisObj:Building=this;
                                //code
                                //in the bBase.onRollOver
                                trace(this._name+">"+(int(this._name.charAt(this._name.length-1))+1)+">"+thisObj.floors);
                                • 13. Re: V2 Components
                                  FlashAmit Level 1
                                  Now how should I refer to 'fName'

                                  class Building extends MovieClip {
                                  [Inspectable]
                                  private var floors:Number;
                                  private var fName:Array;

                                  //code.............
                                  public function createBuilding():Void {
                                  var thisObj:Building=this;
                                  //code
                                  //in the bBase.onRollOver
                                  trace("in>"+thisObj.fName.length);
                                  • 14. Re: V2 Components
                                    Peter Lorent Level 2
                                    You didn't initialize the array.
                                    Either in init or in createBuilding:
                                    fName=new Array();
                                    then your code:
                                    trace("in>"+thisObj.fName.length)
                                    is correct.
                                    • 15. Re: V2 Components
                                      FlashAmit Level 1
                                      Thank you very much. So far i have been finding every thing going on the track.

                                      Now I am using Tween Class.

                                      I included

                                      import mx.transitions.Tween;
                                      import mx.transitions.easing.*;

                                      Replaced the MovieClip.as as described in the help.
                                      then added

                                      for (var i = 1; i<=floors; i++) {
                                      //code...
                                      bBase.targety = gFloor._y-gFloorHeight-((i-2)*floorHeight);
                                      bBase.tween("_y", bBase.targety, 3, "easeOutElastic");

                                      The targety value is coming out as expected.
                                      but its not tweening.....
                                      • 16. Re: V2 Components
                                        Peter Lorent Level 2
                                        >>Replaced the MovieClip.as as described in the help.
                                        Please indicate where you have read that.
                                        • 17. Re: V2 Components
                                          FlashAmit Level 1
                                          See in Flash 8 Help> MovieClip Twening Prototypes> Intructions> Additional Notes.
                                          But there is a confusion that is for Flash MX 2004.

                                          • 18. Re: V2 Components
                                            Peter Lorent Level 2
                                            Couldn't find that topic. Well, the syntax for a tween using the Tween Class would be:

                                            var myTween:Object=new Tween(bBase, "_y", Elastic.easeOut,bBase.targety,[new value],3,true);
                                            or:
                                            var myTween:Tween=new Tween(bBase, "_y", Elastic.easeOut,bBase.targety,[new value],3,true);
                                            if you are targeting > Flash Player 8 (difference in datatype Object/Tween)

                                            where [new value] should be replaced...
                                            • 19. Re: V2 Components
                                              FlashAmit Level 1
                                              The topic html is lying in my PC at
                                              E:\Documents and Settings\amit\Local Settings\Application Data\Macromedia\Flash 8\en\Configuration\HelpPanel\Help\MovieclipTweening
                                              'E' is my root drive

                                              The content i have uploaded here.
                                              • 20. Re: V2 Components
                                                Peter Lorent Level 2
                                                That's not the native Tween Class but a 'third party' tween class - lmc_tween. Can't help you with that. Refer to the documentation for the correct syntax.
                                                At the top of your class you should probably use:
                                                #include "lmc_tween.as"
                                                • 21. Re: V2 Components
                                                  FlashAmit Level 1
                                                  I dropped the use of custom class and go with the native classed.
                                                  Tween worked file.
                                                  Now I want to add a mask so that the floor movie clips appear to be emerging fron the base

                                                  So I added a mask.
                                                  But its not appearing as mask.


                                                  • 22. Re: V2 Components
                                                    Peter Lorent Level 2
                                                    You first create the mask so the mask is lower than the mc you want to mask. The mask should be on top. Also, if you want to mask a series of mc's you need to put those mc's in a container_mc because you cannot apply the same mask on individual mc's.
                                                    • 23. Re: V2 Components
                                                      FlashAmit Level 1
                                                      Please answer few things
                                                      - in the line
                                                      gFloor = fContainer.attachMovie("bGFloor", "bB0", this.getNextHighestDepth());
                                                      Is 'gFloor' is an temporary identifier to the new attached movie clip.

                                                      - in
                                                      var myTweenOnRel:Tween = new Tween(bBase, "_y", "", bBase._y, bBase.targety, 30, false);
                                                      how can I refer this tween again. How can I make a public function that will execute this statement for each attached MC.

                                                      - What is the use of function 'invalidate()'
                                                      - Can I mask dynamic text in V2 components in the same way in AS1.

                                                      • 24. Re: V2 Components
                                                        Peter Lorent Level 2
                                                        In your class definition you have:
                                                        private var gFloor:MovieClip;
                                                        gFloor is an instance property used to store a reference to that newly attached mc. Through the instance you can access the functionality of the MovieClip Class.

                                                        public function tweenFloor(target_mc:MovieClip):Void{
                                                        var myTweenOnRel:Tween = new Tween(target_mc, "_y", "", target_mc._y, target_mc.targety, 30, false);
                                                        }

                                                        invalidate() marks the instance of the component to be redrawn on the next frame interval

                                                        You can mask dynamic text in a V2 component.
                                                        • 25. Re: V2 Components
                                                          FlashAmit Level 1
                                                          The function animates but does not hides the movie clips.
                                                          Please help to find the errors...
                                                          //fName array stores references to the building floor movie clips
                                                          public function popDownBuilding() {
                                                          for (var i = 0; i<=floors; i++) {
                                                          var myTween:Tween = new Tween(fName , "_y", Elastic.easeOut, fName._y, 0, 20, false);
                                                          }
                                                          myTween.onMotionStopped= function() {
                                                          fName ._visible = false;
                                                          };
                                                          }
                                                          • 26. Re: V2 Components
                                                            Peter Lorent Level 2
                                                            Remember to attach the code. Now I don't see the array index parameter and instead the code shows up partly italic. Try the attached code. Will probably fail (only one mc set to invisible) so you probably need to setup a seperate function to hide the mc's.



                                                            • 27. Re: V2 Components
                                                              FlashAmit Level 1
                                                              I am doing the same way but it appears the myTween.onMotionStopped is not executing

                                                              Entire code is uploaded...

                                                              Download Code
                                                              • 28. Re: V2 Components
                                                                Peter Lorent Level 2
                                                                Thought as much because the callback is inside the for loop. Use a seperate function to hide the mc's and call the function in the for loop passing it fName -bracket i bracket - as a parameter.
                                                                • 29. Re: V2 Components
                                                                  Peter Lorent Level 2
                                                                  Something like attached code.

                                                                  • 30. Re: V2 Components
                                                                    FlashAmit Level 1
                                                                    It works all fine. Now I want a text banner along the 30degree line of floors movieclip. I added atext field in the movie clip. But as I skew its text disappear. If I trace the text it is there.
                                                                    I think it has to be done using the Bitmap class and Matrix class. First converting the text to bitmap text and then applying the tranformations.
                                                                    But I am not getting a way to do this....
                                                                    • 31. Re: V2 Components
                                                                      Peter Lorent Level 2
                                                                      Upload the latest code with the text field. Saves me some time.
                                                                      • 32. Re: V2 Components
                                                                        FlashAmit Level 1
                                                                        I was trying this in aseparate file.


                                                                        Code is here....
                                                                        • 33. Re: V2 Components
                                                                          Level 7
                                                                          I was trying this in aseparate file.


                                                                          http://www.sunherbgroup.com/html/testSkew.zip is here....
                                                                          • 34. Re: V2 Components
                                                                            Peter Lorent Level 2
                                                                            Code is fine. Just doesn't work with device fonts. Use another font and embed the ranges you need.
                                                                            • 35. Re: V2 Components
                                                                              FlashAmit Level 1
                                                                              It works now. I am thru with this components. Now I have to integrate this and make a new component. Will get back to you soon...if face any issues related to the integration...

                                                                              Thanks Again.
                                                                              • 36. Re: V2 Components
                                                                                Peter Lorent Level 2
                                                                                You're welcome.
                                                                                • 37. Re: V2 Components
                                                                                  FlashAmit Level 1
                                                                                  I am back with some more questions...


                                                                                  - How should I write following line if I want to call the function with a parameter
                                                                                  btn.onRollOver = myFunction(param);

                                                                                  - In my class Building when I call function popDownBuilding() and popUpBuilding() internally (Line 59,60) it does not work. In fact it does not have the value of 'floors' inside the function.
                                                                                  After putting a instance on the Stage say instance name "a" and calling the above two functions as
                                                                                  a.popDownBuilding();
                                                                                  a.popUpBuilding();
                                                                                  Works well. What shud I modify to work correctly both way.


                                                                                  Latest Code
                                                                                  • 38. Re: V2 Components
                                                                                    Peter Lorent Level 2
                                                                                    Scope problem. Add the following line at the top of the class:
                                                                                    import mx.utils.Delegate;
                                                                                    Change the calls:
                                                                                    bBase.btn.onRollOver = Delegate.create(this,popUpBuilding);
                                                                                    bBase.btn.onRollOut = Delegate.create(this,popDownBuilding);