4 Replies Latest reply on Jul 18, 2010 2:25 PM by Zombiecook KochtVorWut

    Why i can't set an veriable into animation attributes?

    Zombiecook KochtVorWut

      Hello,

      I have an simple question, why i can't put variables into animations ?

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application width="100%" height="100%"
                     xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     xmlns:mx="library://ns.adobe.com/flex/mx">
         
          <fx:Declarations>
              <s:Parallel id="MoveRect_1ToRight">
                  <s:Move xTo="
      {MoveXto}" target="{Rect_1}" duration="8000" />
              </s:Parallel>

          </fx:Declarations>
         
          <fx:Script>
              <![CDATA[
                 
                 
      public var MoveXto:Number = -(Rect_1.width - stage.width);

       

              ]]>
          </fx:Script>
         
          <s:Group id="Rect_1" width="3000" height="800" verticalCenter="0">
              <s:Rect width="100%" height="100%">
                  <s:fill>
                      <s:LinearGradient>
                          <s:GradientEntry color="#e8db03"/>
                          <s:GradientEntry color="#153eec"/>
                      </s:LinearGradient>
                  </s:fill>
              </s:Rect>
          </s:Group>
         
          <s:Group id="Rect_2" width="80" top="0" bottom="0" right="0"
                   rollOver="MoveRect_1ToRight.play();" rollOut="MoveRect_1ToRight.pause();">
              <s:Rect width="100%" height="100%">
                  <s:fill><s:SolidColor color="#000000" alpha="0.2"/></s:fill>
              </s:Rect>
          </s:Group>
      </s:Application>

       

       

      Greetings

      zombiecook

        • 1. Re: Why i can't set an veriable into animation attributes?
          Peter deHaan Level 4

          You'll probably need to make your MoveXto variable bindable using the [Bindable] metadata.

           

          [Bindable]
          public var MoveXto:Number = -(Rect_1.width - stage.width);
          
          

           

           

          Peter

          1 person found this helpful
          • 2. Re: Why i can't set an veriable into animation attributes?
            Zombiecook KochtVorWut Level 1

            Thank you for your fast answer.

            I have tested it and now i get no warning anymore but when i want to start the Application nothing appears.


            When i remove "-(Rect_1.width  - stage.width)" and replace that with some Numbers like "-2800" it works.

            Is there a chance to get it work with this "-(Rect_1.width  -  stage.width)" in it ?

             

             

            • 3. Re: Why i can't set an veriable into animation attributes?
              Shongrunden Adobe Employee

              You need to calculate the value of MoveXto after the application is created, here I use the creationComplete handler as an example (and I changed stage to this), but you might also consider using the applicationComplete handler if you do want a non null stage value.

               

              <?xml version="1.0" encoding="utf-8"?>
              <s:Application width="100%" height="100%"
                             xmlns:fx="http://ns.adobe.com/mxml/2009"
                             xmlns:s="library://ns.adobe.com/flex/spark"
                             xmlns:mx="library://ns.adobe.com/flex/mx"
                             creationComplete="init()">
                 
                  <fx:Declarations>
                      <s:Parallel id="MoveRect_1ToRight">
                          <s:Move xTo="{MoveXto}" target="{Rect_1}" duration="8000" />
                      </s:Parallel>
                  </fx:Declarations>
                 
                  <fx:Script>
                      <![CDATA[
                          [Bindable] public var MoveXto:Number;

                          private function init():void {
                              MoveXto = -1 * (Rect_1.width - this.width);
                          }

                      ]]>
                  </fx:Script>
                 
                  <s:Group id="Rect_1" width="3000" height="800" verticalCenter="0">
                      <s:Rect width="100%" height="100%">
                          <s:fill>
                              <s:LinearGradient>
                                  <s:GradientEntry color="#e8db03"/>
                                  <s:GradientEntry color="#153eec"/>
                              </s:LinearGradient>
                          </s:fill>
                      </s:Rect>
                  </s:Group>
                 
                  <s:Group id="Rect_2" width="80" top="0" bottom="0" right="0"
                           rollOver="MoveRect_1ToRight.play();" rollOut="MoveRect_1ToRight.pause();">
                      <s:Rect width="100%" height="100%">
                          <s:fill><s:SolidColor color="#000000" alpha="0.2"/></s:fill>
                      </s:Rect>
                  </s:Group>
              </s:Application>
              • 4. Re: Why i can't set an veriable into animation attributes?
                Zombiecook KochtVorWut Level 1

                You need to calculate the value of MoveXto after the application is created, here I use the creationComplete handler as an example (and I changed stage to this), but you might also consider using the applicationComplete handler if you do want a non null stage value.

                 

                <?xml version="1.0" encoding="utf-8"?>

                 

                <s:Application width="100%" height="100%"

                 

                               xmlns:fx="http://ns.adobe.com/mxml/2009"

                 

                               xmlns:s="library://ns.adobe.com/flex/spark"

                 

                               xmlns:mx="library://ns.adobe.com/flex/mx"

                 

                               creationComplete="init()">

                 

                   

                 

                    <fx:Declarations>

                 

                       <s:Parallel id="MoveRect_1ToRight">

                 

                            <s:Move xTo="{MoveXto}" target="{Rect_1}" duration="8000" />

                 

                        </s:Parallel>

                 

                    </fx:Declarations>

                 

                   

                 

                    <fx:Script>

                 

                        <![CDATA[

                 

                            [Bindable] public var MoveXto:Number;

                 

                            private function init():void {


                                MoveXto = -1 * (Rect_1.width - this.width);
                            }

                 

                        ]]>
                    </fx:Script>
                   
                    <s:Group id="Rect_1" width="3000" height="800" verticalCenter="0">
                        <s:Rect width="100%" height="100%">
                            <s:fill>
                                <s:LinearGradient>
                                    <s:GradientEntry color="#e8db03"/>
                                    <s:GradientEntry color="#153eec"/>
                                </s:LinearGradient>
                           </s:fill>
                        </s:Rect>
                    </s:Group>
                  
                    <s:Group id="Rect_2" width="80" top="0" bottom="0" right="0"
                            rollOver="MoveRect_1ToRight.play();" rollOut="MoveRect_1ToRight.pause();">
                        <s:Rect width="100%" height="100%">
                            <s:fill><s:SolidColor color="#000000" alpha="0.2"/></s:fill>
                        </s:Rect>
                    </s:Group>
                </s:Application>

                Thank you very much !