17 Replies Latest reply on Jul 8, 2011 1:16 PM by kglad

    Fade in _alpha function

    emotionaljoystick

      Hi, so I'm trying to fade a piece of text that I'm loading via XML in and out (as well as moving it's location in and out).  The fade out part is working fine, and as long as I have a _alpha.100 command where I'm currently calling my "slidein" function (really the fade in function) it works fine. No idea why! I've tried about 100 different placements and I'm stumped.. It's very perplexing.  Any help would be greatly appreciated.

       

      function loadXML(loaded) {
          if (loaded) {
              xmlNode = this.firstChild;
              caption = [];
              //url = [];
              total = xmlNode.childNodes.length;
              for (i=0; i<total; i++) {
                  caption[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
                  //url[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
              }
              first_item();
          } else {
              content = "file not loaded!";
          }
      }
      xmlData = new XML();
      xmlData.ignoreWhite = true;
      xmlData.onLoad = loadXML;
      xmlData.load("newstick.xml");
      //
      newsMC.newsText.autoSize = "center";

       

      function first_item() {
          delay = 0;
          p = 0;
          display(p);
          p++;
      }
      BarrowR.onRelease = function() {
          myInterval = setInterval(ticker, delay);
          function ticker() {
              clearInterval(myInterval);
              if (p == total) {
                  p = 0;
              }
              slideout();
          }
      }
      function display(pos) {
          //newsMC.newsText._x = 51;
          over = new TextFormat();
          over.underline = true;
          //
          out = new TextFormat();
          out.underline = false;
          //
          slidein();
          trace(newsMC.newsText._alpha);
          newsMC.newsText.text = caption[pos];
          //
          newsMC.onRollOver = function() {
              this.newsText.setTextFormat(over);
          };
          newsMC.onRollOut = function() {
              this.newsText.setTextFormat(out);
          };
      }

       

      function slideout() {
          this.onEnterFrame = function() {
              if (newsMC.newsText._x<=330) {
                  newsMC.newsText._x+=10;
              if (newsMC.newsText._alpha>=0) {
                  newsMC.newsText._alpha-=10;
              }} else {
                  newsMC.newsText._x = 191;
                  newsMC.newsText._alpha = 0;
                  display(p);
                  p++;
                  delete this.onEnterFrame;
              }
          };
      }

       

      function slidein() {
          trace(newsMC.newsText._alpha);
          this.onEnterFrame = function() {
              if (newsMC.newsText._alpha<100) {
                  newsMC.newsText._alpha+=10;
              } else {
                  newsMC.newsText._alpha=100;
                  //newsMC.newsText._alpha=100;
                  delete this.onEnterFrame;
              }
          };
      }

       

      stop();

        • 1. Re: Fade in _alpha function
          kglad Adobe Community Professional & MVP

          make sure your textfield has its font embedded:

           


           

          function loadXML(loaded) {
              if (loaded) {
                  xmlNode = this.firstChild;
                  caption = [];
                  //url = [];
                  total = xmlNode.childNodes.length;
                  for (i=0; i<total; i++) {
                      caption[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
                      //url[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
                  }
                  first_item();
              } else {
                  content = "file not loaded!";
              }
          }
          xmlData = new XML();
          xmlData.ignoreWhite = true;
          xmlData.onLoad = loadXML;
          xmlData.load("newstick.xml");
          //
          newsMC.newsText.autoSize = "center";

           

          function first_item() {
              delay = 0;
              p = 0;
              display(p);
              p++;
          }
          BarrowR.onRelease = function() {
              myInterval = setInterval(ticker, delay);
              function ticker() {
                  clearInterval(myInterval);
                  if (p == total) {
                      p = 0;
                  }
                  slideout();
              }
          }
          function display(pos) {
              //newsMC.newsText._x = 51;
              over = new TextFormat();
              over.underline = true;
              //
              out = new TextFormat();
              out.underline = false;
              //
              slidein();
              trace(newsMC.newsText._alpha);
              newsMC.newsText.text = caption[pos];
              //
              newsMC.onRollOver = function() {
                  this.newsText.setTextFormat(over);
              };
              newsMC.onRollOut = function() {
                  this.newsText.setTextFormat(out);
              };
          }

           

          function slideout() {
              this.onEnterFrame = function() {
                 if (newsMC.newsText._x<=330) {
                      newsMC.newsText._x+=10;

          }
                  if (newsMC.newsText._alpha>0) {
                      newsMC.newsText._alpha-=10;
                  } else {
                      newsMC.newsText._x = 191;
                      newsMC.newsText._alpha = 0;
                      display(p);
                      p++;
                      delete this.onEnterFrame;
                  }

              };
          }

           

          function slidein() {
              this.onEnterFrame = function() {
                  if (newsMC.newsText._alpha<100) {
                      newsMC.newsText._alpha+=10;
                  } else {
                      newsMC.newsText._alpha=100;
                      //newsMC.newsText._alpha=100;
                      delete this.onEnterFrame;
                  }
              };
          }

           

          stop();

          1 person found this helpful
          • 2. Re: Fade in _alpha function
            emotionaljoystick Level 1

            The text absolutely has the font embedded.  In fact, that code works fine if you comment out the " slidein();" function and just tell the _alpha to be 100% (it just doesn't fade up).  But the "slideout();" function works great...  Which makes me suspect that the slidein() function isn't running, but I have no idea as to why.

            • 3. Re: Fade in _alpha function
              kglad Adobe Community Professional & MVP

              what do you see when you test the code i suggested?

              • 4. Re: Fade in _alpha function
                emotionaljoystick Level 1

                Sorry, I didn't see that bit you posted.  I tried it, and the "slidein()" function still seems to not be working.  I think I did try setting alpha in that section before too, to no avail... Really stumped..

                • 5. Re: Fade in _alpha function
                  kglad Adobe Community Professional & MVP

                  again, what do you see when you test the code i suggested?

                  • 6. Re: Fade in _alpha function
                    emotionaljoystick Level 1

                    Sorry.  What happens is that the text stays at 0 _alpha....  That seems to correspond with the traces I've set up too, which when I turn them on, all report 0, which I suppose means the slidein(); function is just not running, although I don't know why...  I'm wondering if I should use a tweening engine instead?

                    • 7. Re: Fade in _alpha function
                      kglad Adobe Community Professional & MVP

                      what's the trace output from using:

                       


                       


                       

                      function loadXML(loaded) {
                          if (loaded) {
                              xmlNode = this.firstChild;
                              caption = [];
                              //url = [];
                              total = xmlNode.childNodes.length;
                              for (i=0; i<total; i++) {
                                  caption[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
                                  //url[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
                              }
                              first_item();
                          } else {
                              content = "file not loaded!";
                          }
                      }
                      xmlData = new XML();
                      xmlData.ignoreWhite = true;
                      xmlData.onLoad = loadXML;
                      xmlData.load("newstick.xml");
                      //
                      newsMC.newsText.autoSize = "center";

                       

                      function first_item() {
                          delay = 0;
                          p = 0;
                          display(p);
                          p++;
                      }
                      BarrowR.onRelease = function() {
                          myInterval = setInterval(ticker, delay);
                          function ticker() {
                              clearInterval(myInterval);
                              if (p == total) {
                                  p = 0;
                              }
                              slideout();
                          }
                      }
                      function display(pos) {
                          //newsMC.newsText._x = 51;
                          over = new TextFormat();
                          over.underline = true;
                          //
                          out = new TextFormat();
                          out.underline = false;
                          //
                          slidein();
                      trace(caption[pos]);
                          newsMC.newsText.text = caption[pos];
                          //
                          newsMC.onRollOver = function() {
                              this.newsText.setTextFormat(over);
                          };
                          newsMC.onRollOut = function() {
                              this.newsText.setTextFormat(out);
                          };
                      }

                       

                      function slideout() {
                          this.onEnterFrame = function() {
                             if (newsMC.newsText._x<=330) {
                                  newsMC.newsText._x+=10;

                      }
                              if (newsMC.newsText._alpha>0) {
                                  newsMC.newsText._alpha-=10;
                              } else {
                                  newsMC.newsText._x = 191;
                                  newsMC.newsText._alpha = 0;
                                  display(p);
                                  p++;
                                  delete this.onEnterFrame;
                              }

                          };
                      }

                       

                      function slidein() {
                          this.onEnterFrame = function() {
                              if (newsMC.newsText._alpha<100) {
                                  newsMC.newsText._alpha+=10;
                              } else {
                                  newsMC.newsText._alpha=100;
                                  trace(newsMC.newsText._alpha);
                                  delete this.onEnterFrame;
                              }
                          };
                      }

                       

                      stop();

                      1 person found this helpful
                      • 8. Re: Fade in _alpha function
                        emotionaljoystick Level 1

                        The trace for the caption[pos] returns the proper headline drawn from the .xml file.  And it's the right one (it's cycling through) every time the button is pressed.  Here is something interesting:  The first time the text is loaded, the second trace you set up reports back with an alpha of 100, but each time I press the button, it doesn't report at all.  Does that just mean that the function is not running?

                        • 9. Re: Fade in _alpha function
                          kglad Adobe Community Professional & MVP

                          i know you think you're giving me extra information and you think that extra information will solve the problem sooner but you're incorrect.

                           

                          if you copy the trace output and paste here we'll solve this problem sooner rather than later.  it's ok to add comments if you want to explain something but failing to follow directions just delays and/or prevents solving your problem.

                          1 person found this helpful
                          • 10. Re: Fade in _alpha function
                            emotionaljoystick Level 1

                            Here is what the code looks like now:

                             

                            function loadXML(loaded) {
                                if (loaded) {
                                    xmlNode = this.firstChild;
                                    caption = [];
                                    //url = [];
                                    total = xmlNode.childNodes.length;
                                    for (i=0; i<total; i++) {
                                        caption[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
                                        //url[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
                                    }
                                    first_item();
                                } else {
                                    content = "file not loaded!";
                                }
                            }
                            xmlData = new XML();
                            xmlData.ignoreWhite = true;
                            xmlData.onLoad = loadXML;
                            xmlData.load("newstick.xml");
                            //
                            newsMC.newsText.autoSize = "center";

                             

                            function first_item() {
                                delay = 0;
                                p = 0;
                                display(p);
                                p++;
                            }
                            BarrowR.onRelease = function() {
                                myInterval = setInterval(ticker, delay);
                                function ticker() {
                                    clearInterval(myInterval);
                                    if (p == total) {
                                        p = 0;
                                    }
                                    slideout();
                                }
                            }
                            function display(pos) {
                                //newsMC.newsText._x = 51;
                                over = new TextFormat();
                                over.underline = true;
                                //
                                out = new TextFormat();
                                out.underline = false;
                                //
                                slidein();
                                trace(newsMC.newsText._alpha);
                                //newsMC.newsText._alpha=100;
                                trace(caption[pos]);
                                newsMC.newsText.text = caption[pos];
                                //
                                newsMC.onRollOver = function() {
                                    this.newsText.setTextFormat(over);
                                };
                                newsMC.onRollOut = function() {
                                    this.newsText.setTextFormat(out);
                                };
                            }

                             

                            function slideout() {
                                this.onEnterFrame = function() {
                                   if (newsMC.newsText._x<=330) {
                                        newsMC.newsText._x+=10;

                             

                            }
                                    if (newsMC.newsText._alpha>0) {
                                        newsMC.newsText._alpha-=10;
                                    } else {
                                        newsMC.newsText._x = 191;
                                        newsMC.newsText._alpha = 0;
                                        display(p);
                                        p++;
                                        delete this.onEnterFrame;
                                    }
                                };
                            }

                             

                            function slidein() {
                                trace(newsMC.newsText._alpha);
                                this.onEnterFrame = function() {
                                    if (newsMC.newsText._alpha<100) {
                                        newsMC.newsText._alpha+=10;
                                    } else {
                                        //newsMC.newsText._alpha=100;
                                        trace(newsMC.newsText._alpha);
                                        delete this.onEnterFrame;
                                    }
                                };
                            }

                             

                            stop();

                             

                             

                            Here is the output:

                             

                            100
                            100
                            Jim DeMint: Why Are Taxpayers Paying for Wine Tasting?
                            100

                            //Button press:

                            0
                            0
                            Merchants Shred Costs of Payments by Plastic

                            //Button press:

                            0
                            0
                            Lawyers Settle... for Temp Jobs

                            • 11. Re: Fade in _alpha function
                              kglad Adobe Community Professional & MVP

                              just use the code i suggest.  don't add extra trace statements.  you're making this way more difficult than it should be.

                               

                              use the code below, and copy and paste the output.  noting when you press a button is helpful like you did above:

                               

                              emotionaljoystick wrote:

                               

                              Here is what the code looks like now:

                               

                              function loadXML(loaded) {
                                  if (loaded) {
                                      xmlNode = this.firstChild;
                                      caption = [];
                                      //url = [];
                                      total = xmlNode.childNodes.length;
                                      for (i=0; i<total; i++) {
                                          caption[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue;
                                          //url[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue;
                                      }
                                      first_item();
                                  } else {
                                      content = "file not loaded!";
                                  }
                              }
                              xmlData = new XML();
                              xmlData.ignoreWhite = true;
                              xmlData.onLoad = loadXML;
                              xmlData.load("newstick.xml");
                              //
                              newsMC.newsText.autoSize = "center";

                               

                              function first_item() {
                                  delay = 0;
                                  p = 0;
                                  display(p);
                                  p++;
                              }
                              BarrowR.onRelease = function() {
                                  myInterval = setInterval(ticker, delay);
                                  function ticker() {
                                      clearInterval(myInterval);
                                      if (p == total) {
                                          p = 0;
                                      }
                                      slideout();
                                  }
                              }
                              function display(pos) {
                                  //newsMC.newsText._x = 51;
                                  over = new TextFormat();
                                  over.underline = true;
                                  //
                                  out = new TextFormat();
                                  out.underline = false;
                                  //


                                  slidein();

                                  //newsMC.newsText._alpha=100;

                                  newsMC.newsText.text = caption[pos];
                                  //
                                  newsMC.onRollOver = function() {
                                      this.newsText.setTextFormat(over);
                                  };
                                  newsMC.onRollOut = function() {
                                      this.newsText.setTextFormat(out);
                                  };
                              }

                               

                              function slideout() {
                                  this.onEnterFrame = function() {
                                     if (newsMC.newsText._x<=330) {
                                          newsMC.newsText._x+=10;

                               

                              }
                                      if (newsMC.newsText._alpha>0) {
                                          newsMC.newsText._alpha-=10;
                                      } else {
                                          newsMC.newsText._x = 191;
                                          newsMC.newsText._alpha = 0;
                                          display(p);
                                          p++;
                                          delete this.onEnterFrame;
                                      }
                                  };
                              }

                               

                              function slidein() {
                                 trace("slidein(): "+this);
                                  this.onEnterFrame = function() {

                              trace("enterframe");
                                      if (newsMC.newsText._alpha<100) {
                                          newsMC.newsText._alpha+=10;
                                      } else {
                                          //newsMC.newsText._alpha=100;
                                          trace(newsMC.newsText._alpha);
                                          delete this.onEnterFrame;
                                      }
                                  };
                              }

                               

                              stop();

                               

                               

                              1 person found this helpful
                              • 12. Re: Fade in _alpha function
                                emotionaljoystick Level 1

                                Sorry man. Didn't see that.

                                 

                                Output:

                                 

                                slidein(): _level0.mcHEAD
                                enterframe
                                100

                                • 13. Re: Fade in _alpha function
                                  kglad Adobe Community Professional & MVP

                                  wow.

                                   

                                  you need to click a button to see the problem, correct?  so, you'll need to click a button to have the trace() statements show what's happening when the problem occurs.

                                  • 14. Re: Fade in _alpha function
                                    emotionaljoystick Level 1

                                    Wow indeed.  Kind of can't believe you're still helping, just trying to do exactly what you're asking...

                                     

                                    slidein(): _level0.mcHEAD
                                    enterframe
                                    100

                                    //Button press
                                    slidein(): _level0.mcHEAD

                                    • 15. Re: Fade in _alpha function
                                      kglad Adobe Community Professional & MVP

                                      ok, you can remove all the trace() funcitons.

                                       

                                      the problem is caused by your enterframe loop (in slidein() ) being overwritten by the enterframe loop in slideout().

                                       

                                      to remedy, use a different movieclip for the slidein() and slideout() enterframe loops.  for example:

                                       

                                       

                                       

                                       

                                      var mc_loop1:MovieClip=this.createEmptyMovieClip("mc_loop1",this.getNextHighestDepth());

                                      var mc_loop2:MovieClip=this.createEmptyMovieClip("mc_loop2",this.getNextHighestDepth());

                                       

                                      function slideout() {
                                         mc_loop1.onEnterFrame = function() {
                                              if (newsMC.newsText._x<=330) {
                                                  newsMC.newsText._x+=10;

                                      }
                                              if (newsMC.newsText._alpha>0) {
                                                  newsMC.newsText._alpha-=10;
                                              } else {
                                                  newsMC.newsText._x = 191;
                                                  newsMC.newsText._alpha = 0;
                                                  display(p);
                                                  p++;
                                                  delete this.onEnterFrame;
                                              }
                                          };
                                      }

                                       

                                      function slidein() {
                                         mc_loop2.onEnterFrame = function() {
                                              if (newsMC.newsText._alpha<100) {
                                                  newsMC.newsText._alpha+=10;
                                              } else {
                                                  newsMC.newsText._alpha=100;
                                                  //newsMC.newsText._alpha=100;
                                                  delete this.onEnterFrame;
                                              }
                                          };
                                      }

                                       

                                      stop();

                                      • 16. Re: Fade in _alpha function
                                        emotionaljoystick Level 1

                                        Cool!  I would not have thought that an issue.  Thank you...

                                        • 17. Re: Fade in _alpha function
                                          kglad Adobe Community Professional & MVP

                                          you're welcome.

                                           

                                          p.s.  please mark helpful/correct responses.