29 Replies Latest reply on Sep 22, 2011 8:12 AM by melas076

    image and text change when sublink clicked

    melas076 Level 1

      Dear,

       

      I would like to know how can i appear an image when i clicked on sublink?

       

      I have 3 MCs: sub_bg, ImgMc and bg.

       

       

      the code's sub_bg is :

       

      function linkF(s:String):Void

      {

        _root.bg.txt.htmlText = s;

      }

       

      the code's bg is:

       

      stop();

      var styles = new TextField.StyleSheet();

      styles.load("css/main.css");

       

      _root.bg.txt.html = true;

      _root.bg.txt.styleSheet = styles;

      _root.sub_bg.subTXT.html = true;

      _root.sub_bg.subTXT.styleSheet = styles;

       

      var newsXML:XML = new XML();

      newsXML.ignoreWhite = true;

      newsXML.onLoad = function(success) {

              if (success) {

       

      var defaultp:String =  newsXML.childNodes[0].childNodes[1].childNodes[0].firstChild.nodeValue;

      _root.bg.txt.text = defaultp;

       

          for(var i:Number=0;i<newsXML.firstChild.childNodes[1].childNodes.length;i++){

      var tlink:String = newsXML.childNodes[0].childNodes[1].attributes.Name;

      var linkS:String = newsXML.childNodes[0].childNodes[1].childNodes[i].attributes.name;

      var imageS:String = newsXML.childNodes[0].childNodes[1].childNodes[i].attributes.ImgUrl;

      var textS:String = newsXML.childNodes[0].childNodes[1].childNodes[i].childNodes;

       

      _root.sub_bg.subTXT.htmlText += "<a href='asfunction:linkF,"+textS+"'>"+linkS+"</a><br>";

      _root.sub_bg.linktitle.htmlText = tlink;

       

      }

          }

      }

       

      newsXML.load("xml/homes.xml");

       

      I will appreciate your help.

       

      regards,

      MELAS

       

      Message was edited by: melas076

        • 1. Re: image and text change when sublink clicked
          kglad Adobe Community Professional & MVP

          where's linkF()?

          • 2. Re: image and text change when sublink clicked
            melas076 Level 1

            in sub_bg MC..... i tried this :

             

            function linkF(s:String):Void

            {

              _root.bg.txt.htmlText = s;

              _root.ImgMC.loadMovie(imageS);

             

            }

             

            and in bg MC :

             

            _root.sub_bg.subTXT.htmlText += "<a href='asfunction:linkF,"+textS+","+imageS+"'>"+linkS+"</a><br>";

             

            but not working;

             

            any help plz!!!!

             

            Regards,

            MELAS

            • 3. Re: image and text change when sublink clicked
              kglad Adobe Community Professional & MVP

              it needs to be on the same timeline as the code below...

               

              stop();

              var styles = new TextField.StyleSheet();

              styles.load("css/main.css");

               

              _root.bg.txt.html = true;

              _root.bg.txt.styleSheet = styles;

              _root.sub_bg.subTXT.html = true;

              1 person found this helpful
              • 4. Re: image and text change when sublink clicked
                melas076 Level 1

                it worked but just load one picture and also when i click on submenu it doesn't change the image with text

                 

                any help!

                 

                Regards,

                MELAS

                • 5. Re: image and text change when sublink clicked
                  melas076 Level 1

                  i tried this code :

                   

                  _root.ImgMC.loadMovie(''+imageS+'');

                   

                  unfornately it doesn't works still

                   

                  any suggestion or help please!!!!

                   

                  regards,

                  MELAS

                  • 6. Re: image and text change when sublink clicked
                    kglad Adobe Community Professional & MVP

                    the only thing you're doing is displaying textS.  you're not doing anything with imageS in linkF()

                     

                    p.s.  please mark helpfull/correct responses.

                    1 person found this helpful
                    • 7. Re: image and text change when sublink clicked
                      melas076 Level 1

                      dear Kglad,

                       

                      I did helpfull/correct responses on your last post.

                       

                      but I need to show image in ImgMC and Text in bg MC when i clicked on sublink.... i tried several time but i didn't find ....

                       

                      _root.sub_bg.subTXT.htmlText += "<a href='asfunction:linkF,"+textS+", "+imageS+"'>"+linkS+"</a><br>";

                      _root.sub_bg.linktitle.htmlText = tlink;

                      _root.ImgMC.loadMovie(+imageS+);

                       

                       

                      any help!!!

                       

                      regards,

                      MELAS

                      • 8. Re: image and text change when sublink clicked
                        kglad Adobe Community Professional & MVP

                        use:

                         

                         

                         

                        function linkF(s:String,s2:String):Void

                        {

                          _root.bg.txt.htmlText = s;

                        _root.ImgMC.loadMovie(s2');

                        }

                         

                         

                         

                        stop();

                        var styles = new TextField.StyleSheet();

                        styles.load("css/main.css");

                         

                        _root.bg.txt.html = true;

                        _root.bg.txt.styleSheet = styles;

                        _root.sub_bg.subTXT.html = true;

                        _root.sub_bg.subTXT.styleSheet = styles;

                         

                        var newsXML:XML = new XML();

                        newsXML.ignoreWhite = true;

                        newsXML.onLoad = function(success) {

                                if (success) {

                         

                        var defaultp:String =  newsXML.childNodes[0].childNodes[1].childNodes[0].firstChild.nodeValu e;

                        _root.bg.txt.text = defaultp;

                         

                            for(var i:Number=0;i<newsXML.firstChild.childNodes[1].childNodes.length;i++){

                        var tlink:String = newsXML.childNodes[0].childNodes[1].attributes.Name;

                        var linkS:String = newsXML.childNodes[0].childNodes[1].childNodes[i].attributes.name;

                        var imageS:String = newsXML.childNodes[0].childNodes[1].childNodes[i].attributes.ImgUrl;

                        var textS:String = newsXML.childNodes[0].childNodes[1].childNodes[i].childNodes;

                         

                        _root.sub_bg.subTXT.htmlText += "<a href='asfunction:linkF,"+textS+","+imageS+"'>"+linkS+"</a><br>";

                        _root.sub_bg.linktitle.htmlText = tlink;

                         

                        }

                            }

                        }

                         

                        newsXML.load("xml/homes.xml");

                        • 9. Re: image and text change when sublink clicked
                          melas076 Level 1

                          thanks so much Klad!!!!!

                          • 10. Re: image and text change when sublink clicked
                            kglad Adobe Community Professional & MVP

                            you're welcome.

                            • 11. Re: image and text change when sublink clicked
                              melas076 Level 1

                              i tested your code but don't worked...

                               

                              it showed me in _root.bg.txt.htmlText the s and s2 texts

                              and nothing in ImgMC also i added trace() to see the s2 but nothing....

                               

                               

                              function linkF(s:String,s2:String):Void

                              {

                                _root.bg.txt.htmlText = s;

                                _root.ImgMC.loadMovie(s2);

                                trace(s2);

                               

                              }

                               

                              it gives me "undefined".

                              why?

                              • 12. Re: image and text change when sublink clicked
                                kglad Adobe Community Professional & MVP

                                because you're not using:

                                 

                                _root.sub_bg.subTXT.htmlText += "<a href='asfunction:linkF,"+textS+","+imageS+"'>"+linkS+"</a><br>";

                                 

                                or newsXML.childNodes[0].childNodes[1].childNodes[i].attributes.ImgUrl is undefined in your for-loop.  use the trace() to debug if it's the later.

                                • 13. Re: image and text change when sublink clicked
                                  melas076 Level 1

                                  i swear i added and nothing want to work!!!!

                                   

                                  see my code:

                                   

                                  stop();

                                  var styles = new TextField.StyleSheet();

                                  styles.load("css/main.css");

                                   

                                  _root.bg.txt.html = true;

                                  _root.bg.txt.styleSheet = styles;

                                  _root.sub_bg.subTXT.html = true;

                                  _root.sub_bg.subTXT.styleSheet = styles;

                                   

                                  var newsXML:XML = new XML();

                                  newsXML.ignoreWhite = true;

                                  newsXML.onLoad = function(success) {

                                          if (success) {

                                     

                                  var defaultp:String =  newsXML.childNodes[0].childNodes[1].childNodes[0].firstChild.nodeValue;

                                  _root.bg.txt.text = defaultp;

                                   

                                      for(var i:Number=0;i<newsXML.firstChild.childNodes[1].childNodes.length;i++){

                                  var tlink:String = newsXML.childNodes[0].childNodes[1].attributes.Name;

                                  var linkS:String = newsXML.childNodes[0].childNodes[1].childNodes[i].attributes.name;

                                  var imageS:String = newsXML.childNodes[0].childNodes[1].childNodes[i].attributes.ImgUrl;

                                  var textS:String = newsXML.childNodes[0].childNodes[1].childNodes[i].childNodes;

                                   

                                  _root.sub_bg.subTXT.htmlText += "<a href='asfunction:linkF,"+textS+","+imageS+"'>"+linkS+"</a><br>";

                                  _root.sub_bg.linktitle.htmlText = tlink;

                                   

                                   

                                  }

                                      }

                                  }

                                   

                                  newsXML.load("xml/homes.xml");

                                   

                                  when i put _root.ImgMC.loadMovie(imageS);  with this code, it works well...

                                   

                                  any help!!!

                                   

                                  regards,

                                  MELAS

                                  • 14. Re: image and text change when sublink clicked
                                    kglad Adobe Community Professional & MVP

                                    where's linkF()??

                                     

                                    again, use:

                                     

                                    function linkF(s:String,s2:String):Void

                                    {

                                      _root.bg.txt.htmlText = s;

                                    _root.ImgMC.loadMovie(s2');

                                    }

                                     

                                     

                                     

                                    stop();

                                    var styles = new TextField.StyleSheet();

                                    styles.load("css/main.css");

                                     

                                    _root.bg.txt.html = true;

                                    _root.bg.txt.styleSheet = styles;

                                    _root.sub_bg.subTXT.html = true;

                                    _root.sub_bg.subTXT.styleSheet = styles;

                                     

                                    var newsXML:XML = new XML();

                                    newsXML.ignoreWhite = true;

                                    newsXML.onLoad = function(success) {

                                            if (success) {

                                     

                                    var defaultp:String =  newsXML.childNodes[0].childNodes[1].childNodes[0].firstChild.nodeValu e;

                                    _root.bg.txt.text = defaultp;

                                     

                                        for(var i:Number=0;i<newsXML.firstChild.childNodes[1].childNodes.length;i++){

                                    var tlink:String = newsXML.childNodes[0].childNodes[1].attributes.Name;

                                    var linkS:String = newsXML.childNodes[0].childNodes[1].childNodes[i].attributes.name;

                                    var imageS:String = newsXML.childNodes[0].childNodes[1].childNodes[i].attributes.ImgUrl;

                                    var textS:String = newsXML.childNodes[0].childNodes[1].childNodes[i].childNodes;

                                     

                                    _root.sub_bg.subTXT.htmlText += "<a href='asfunction:linkF,"+textS+","+imageS+"'>"+linkS+"</a><br>";

                                    _root.sub_bg.linktitle.htmlText = tlink;

                                     

                                    }

                                        }

                                    }

                                    ////////////////////////////

                                    if that fails, use the trace() function in your for-loop and in linkF()

                                    • 15. Re: image and text change when sublink clicked
                                      melas076 Level 1

                                      i did it and not working yet

                                       

                                      see my code:

                                      in sub_bg:

                                      function linkF(s:String,s2:String):Void

                                      {

                                        _root.bg.txt.htmlText = s;

                                        _root.ImgMC.loadMovie(s2);

                                        //trace(s2);

                                       

                                      }

                                       

                                      in bg:

                                       

                                      stop();

                                      var styles = new TextField.StyleSheet();

                                      styles.load("css/main.css");

                                       

                                      _root.bg.txt.html = true;

                                      _root.bg.txt.styleSheet = styles;

                                      _root.sub_bg.subTXT.html = true;

                                      _root.sub_bg.subTXT.styleSheet = styles;

                                       

                                      var newsXML:XML = new XML();

                                      newsXML.ignoreWhite = true;

                                      newsXML.onLoad = function(success) {

                                              if (success) {

                                       

                                      var defaultp:String =  newsXML.childNodes[0].childNodes[1].childNodes[0].firstChild.nodeValue;

                                      _root.bg.txt.text = defaultp;

                                       

                                          for(var i:Number=0;i<newsXML.firstChild.childNodes[1].childNodes.length;i++){

                                      var tlink:String = newsXML.childNodes[0].childNodes[1].attributes.Name;

                                      var linkS:String = newsXML.childNodes[0].childNodes[1].childNodes[i].attributes.name;

                                      var imageS:String = newsXML.childNodes[0].childNodes[1].childNodes[i].attributes.ImgUrl;

                                      var textS:String = newsXML.childNodes[0].childNodes[1].childNodes[i].childNodes;

                                       

                                      _root.sub_bg.subTXT.htmlText += "<a href='asfunction:linkF,"+textS+","+imageS+"'>"+linkS+"</a><br>";

                                      _root.sub_bg.linktitle.htmlText = tlink;

                                       

                                      //_root.ImgMC.loadMovie(imageS);

                                      //trace(imageS);

                                       

                                      }

                                          }

                                      }

                                       

                                      newsXML.load("xml/homes.xml");

                                       

                                      it writes in _root.bg.txt.text like in image attached.

                                       

                                      in sub_bg trace is undefined but in bg I see images/home/1.jpg and images/home/2.jpg

                                       

                                      where is the issues?

                                       

                                       

                                       

                                      thanks in advance.

                                      MELAS

                                       

                                       

                                       

                                       

                                       

                                      test-1.jpg

                                      • 16. Re: image and text change when sublink clicked
                                        melas076 Level 1

                                        Dear Kglad,

                                         

                                        I didn't get any idea for this. please help me....

                                         

                                        Regards,

                                        MELAS

                                        • 17. Re: image and text change when sublink clicked
                                          melas076 Level 1

                                          MR Kglad,

                                           

                                          I solved it but thanks you very much for your time spent with me.

                                           

                                          you missed something in the code but i don't know you know this or not

                                           

                                          regards,

                                          MELAS

                                          • 18. Re: image and text change when sublink clicked
                                            kglad Adobe Community Professional & MVP

                                            you're welcome.

                                            • 19. Re: image and text change when sublink clicked
                                              melas076 Level 1

                                              dear Kglad,

                                               

                                              i want to know how to reset the autosize of TextField, because i set _root.mc.TextField.autosize = true; then when i clicked on sublink the size didn't change....

                                               

                                              how?

                                               

                                              regards,

                                              MELAS

                                              • 20. Re: image and text change when sublink clicked
                                                kglad Adobe Community Professional & MVP

                                                try:

                                                 

                                                _root.mc.textfield.autoSize="left";  // don't use TextField for an instance name.

                                                • 21. Re: image and text change when sublink clicked
                                                  melas076 Level 1

                                                  i did but i don't see any change......

                                                   

                                                  because my scrollbar is the same, it takes the first time the size of textfield on load..... then when i click on submenu it doesn't reset the scrollbar for textfield....

                                                   

                                                  any idea?

                                                   

                                                  regards,

                                                  MELAS

                                                  • 22. Re: image and text change when sublink clicked
                                                    kglad Adobe Community Professional & MVP

                                                    that's because you almost certainly don't know the path to your textfield.  to confirm, use:

                                                     

                                                    trace(_root.mc.textfield);  // use the correct textfield instance name.

                                                    • 23. Re: image and text change when sublink clicked
                                                      melas076 Level 1

                                                      it is correct path, but i think you didn't understand me.....

                                                       

                                                      the first, Textfield loaded Text and scrollbar works.

                                                      then, when i click on one of the sublink, it changes text in the correct _root.mc.TextField, it changes Text but scrollbar not work.

                                                      the scrollbar is taking the size of the first time Textfield loaded but it is scrollable with not correct Textfield size....

                                                       

                                                      I hope you understood me ..

                                                       

                                                      Thanks in advance..

                                                       

                                                      regards,

                                                      MELAS

                                                      • 24. Re: image and text change when sublink clicked
                                                        kglad Adobe Community Professional & MVP

                                                        what's

                                                         

                                                        trace(_root.mc.TextField)

                                                         

                                                        show?

                                                        • 25. Re: image and text change when sublink clicked
                                                          melas076 Level 1

                                                          When i trace, it gives me this : _level0.bg_home.content_mc2.txt

                                                          • 26. Re: image and text change when sublink clicked
                                                            kglad Adobe Community Professional & MVP

                                                            i don't understand what you're trying to do.

                                                            • 27. Re: image and text change when sublink clicked
                                                              melas076 Level 1

                                                              i am trying to do about the scrollbar.

                                                               

                                                              the first, Textfield loaded Text and scrollbar works.

                                                              then, when i click on one of the sublink, it changes text in the correct _root.mc.TextField, it changes Text but scrollbar not work because it doesn't change the content._height

                                                              the scrollbar is taking the same size of the first time Textfield loaded but it is scrollable with not correct content._height size.

                                                               

                                                              regards,

                                                              MELAS

                                                              • 28. Re: image and text change when sublink clicked
                                                                kglad Adobe Community Professional & MVP

                                                                the scrollbar doesn't work, at all?  or, it works but doesn't scroll the correct amount of text?

                                                                • 29. Re: image and text change when sublink clicked
                                                                  melas076 Level 1

                                                                  yes it works but when i clicked on sublink which has a small text, so the scrollbar will disappear normally.....

                                                                   

                                                                  anyway i solved today....

                                                                   

                                                                  thanks a lot for your help!

                                                                   

                                                                  do you have any idea for the scrollbar which i posted last 2 days in a new post?

                                                                   

                                                                  regards,

                                                                  MELAS