3 Replies Latest reply on Mar 2, 2013 6:25 AM by chuba21

    How can I reference the symbol that contains the code.

    chuba21 Level 2

      I am trying to create a circle that is dynamically added to the stage.

       

      Iwant to add all of the programatic animations in the symbol's stage but I can't figure out how to reference teh symbol itself with something I use to do in AS3 using the keyword this

       

      For example:

       

      - I create a symbol called Light, with a png inside

      - I open it and place a series of code lines

       

      var myW = this.width(); // how to reference the symbol from itself? this and $(this) and $('this') dont work.

      var myH = this.height();

       

      funciton init()

      {

           this.getSymbolElement().css("left", Math.random() * 1024);

           this.getSymbolElement().css("top", Math.random() * 768);

           this.getSymbolElement().css("scale", 1); // how to reset the scale?

           TweenMax.to(this, 2 + Math.random()*4,{opacity:0, scale:4, delay:Math.random()*10, onComplete:init});

      }

       

      init();

       

      So each time the TweenMax completes the action, the symbol changes its position and resets the scale (how to reset it is another question)

      After that I create n instances of the symbol with a for loop and scatter them over the stage randomly.

       

       

      A

        • 1. Re: How can I reference the symbol that contains the code.
          elainecc Adobe Employee

          Hi, chuba-

           

          So you will probably want to put the init code into your symbol definition's creationComplete event, which is the equivalent of a constructor function.  From there, you can use sym.getSymbolElement() instead of this.getSymbolElement() to grab the handle of the current instance and make your manipulation.

           

          On the Stage's compositionReady event handler (or in a trigger/user generated event), you can then call sym.createChildSymbol("symbolDefinitionName") in a for loop to get your instances populating on the stage.

           

          Hope that helps!

           

          -Elaine

          • 2. Re: How can I reference the symbol that contains the code.
            CindyJones-Hulfachor Level 1

            If by chance you copied and pasted your code here, I see that you have the word function spelled wrong.

            • 3. Re: How can I reference the symbol that contains the code.
              chuba21 Level 2

              Thank Cindy it was dummy code typed here.

               

              This worked perfectly! So here is how I did my PARTICLE SYSTEM:

               

              var root = sym.getSymbolElement();

              root.css("position", "absolute");

               

               

              var myW = root.width();

              var myH = root.height();

               

               

              function init()

              {

                        var lightX = 40 + Math.random() * (1036 - 80);

                        var lightY = 30 + Math.random() * 170;

                        root.css("opacity", 1);

                        root.css("transform","scale(0)").css("-moz-transform","scale(0)").css("-webkit-trans form","scale(0)");

                        root.css("left", lightX);

                        root.css("top", lightY);

                        TweenMax.to(root, 0.5 + Math.random() * 1.5, {opacity:0, scale:3, delay:Math.random()*2, onComplete:init});

              }

               

               

              init();