27 Replies Latest reply on Dec 20, 2010 11:02 AM by Ex0skelet0r

    Problem on creating a button with as2

    Ex0skelet0r Level 1

      I have buy a template with the following code that loads a logo

      _root.createEmptyMovieClip("logo",_root.getNextHighestDepth());
      
       _root.createEmptyMovieClip("menuholder",_root.getNextHighestDepth());
       _root.attachMovie("mbg","menumask",_root.getNextHighestDepth(),{_width:960, _height:Stage.height,_x:(Stage.width/2)-480, _y:_root.menuholder._y, _alpha:0});
      
      logoLoad(XMLoptions_logourl,_root.logo); 
      
      
      initHeader = function () {
       logoLoad = function (path, targetMovie) {
       targetMovie._alpha = 0;
       var my_mcl:MovieClipLoader = new MovieClipLoader();
       var mclListener:Object = new Object();
       my_mcl.addListener(mclListener);
       mclListener.onLoadInit = function() {
       targetMovie._y = _root.XMLoptions_headerheight-Math.floor((XMLoptions_logoheight/2)+(XMLoptions_menuheight/2))-XMLoptions_logopaddingy;
       Tweener.addTween(targetMovie,{_alpha:100, time:1, transition:"easeOutSine"});
       //
       //LOGO ORIENTATION
       //
       if(XMLoptions_logoorientation=="right"){
       targetMovie._x = Math.floor((Stage.width/2)+480-targetMovie._width-XMLoptions_logopaddingx);
       }else if(XMLoptions_logoorientation=="center"){
       targetMovie._x = (Stage.width/2)-(targetMovie._width/2);
       }else if(XMLoptions_logoorientation=="left"){
       targetMovie._x = Math.floor((Stage.width/2)-480)+XMLoptions_logopaddingx;
       }
       };
       my_mcl.loadClip(path,targetMovie);
       };
      

       

       

      I want to add another logo that will be in the right if the logo is on the left, and i want that logo to have a rollover effect like a button so i add this code

       

      _root.createEmptyMovieClip("logo2",_root.getNextHighestDepth());
      logo2Load(XMLoptions_logo2url,_root.logo2);
      
      
      logo2Load = function (path, targetMovie) {
       targetMovie._alpha = 0;
       var my_mcl:MovieClipLoader = new MovieClipLoader();
       var mclListener:Object = new Object();
       my_mcl.addListener(mclListener);
       mclListener.onLoadInit = function() {
       targetMovie._y = _root.XMLoptions_headerheight-Math.floor((XMLoptions_logoheight/2)+(XMLoptions_menuheight/2))-XMLoptions_logopaddingy;
       Tweener.addTween(targetMovie,{_alpha:100, time:1, transition:"easeOutSine"});
       //
       //LOGO ORIENTATION
       //
       //test=false;
       if (test==true){
       if(XMLoptions_logoorientation=="right"){
       targetMovie._x = Math.floor((Stage.width/2)-480)+XMLoptions_logopaddingx;
       }else if(XMLoptions_logoorientation=="center"){
       targetMovie._x = (Stage.width/2)-(targetMovie._width/2);
       }else if(XMLoptions_logoorientation=="left"){
       targetMovie._x = Math.floor((Stage.width/2)+480-targetMovie._width-XMLoptions_logopaddingx);
       }}test=true;
       targetMovie.onRollOver = function(){
       logo3Load(XMLoptions_logo2over,_root.logo2);
       };
       
       
       };
       my_mcl.loadClip(path,targetMovie);
       };
       //
       logo3Load = function (path, targetMovie) {
       targetMovie._alpha = 0;
       var my_mcl:MovieClipLoader = new MovieClipLoader();
       var mclListener:Object = new Object();
       my_mcl.addListener(mclListener);
       mclListener.onLoadInit = function() {
       targetMovie._y = _root.XMLoptions_headerheight-Math.floor((XMLoptions_logoheight/2)+(XMLoptions_menuheight/2))-XMLoptions_logopaddingy;
       Tweener.addTween(targetMovie,{_alpha:100, time:1, transition:"easeOutSine"});
       //
       //LOGO ORIENTATION
       //
       
       
       targetMovie.onRelease = function(){
       getURL(XMLoptions_urlredirect, "_self"); 
       
       };
       targetMovie.onRollOut = function(){
       //Tweener.removeTweens(_root.footer.tooltip);
       //removeMovieClip(_root.footer.tooltip);
       test=false;
       logo2Load(XMLoptions_logo2url,_root.logo2);
       };
       
       };
       my_mcl.loadClip(path,targetMovie);
       };
      

       

       

      Which makes the page sometimes do strange things cause im loading the logo again instead of changing the image, What is the correct way to change the image XMLoptions_logo2url on XMLoptions_logo2over on rollover?

        • 1. Re: Problem on creating a button with as2
          kglad Adobe Community Professional & MVP

          why are you executing

          logo2Load(XMLoptions_logo2url,_root.logo2);

          twice?  that should only execute once.

          • 2. Re: Problem on creating a button with as2
            Ex0skelet0r Level 1

            if i execute it only once, after the mouse rollover,  the image doesnt return to the previous state

            • 3. Re: Problem on creating a button with as2
              kglad Adobe Community Professional & MVP

              you're creating a movieclip button.  you want one image to be visible on rollover and a different image to be visible on rollout?  if that's true, you shouldn't be loading those images.

              • 4. Re: Problem on creating a button with as2
                Ex0skelet0r Level 1

                yes.

                which way is the best way? i can do it with the timeline gotoandplay etc?

                I want to be in the position targetMovie._x = Math.floor((Stage.width/2)+480-targetMovie._width-XMLoptions_logopaddingx);

                • 5. Re: Problem on creating a button with as2
                  kglad Adobe Community Professional & MVP

                  because there'a a delay when loading (even small) files, it's generally unsatisfactory to dynamically load images for rollover and rollout display.

                   

                  the images can still be preloaded into different target movieclips and used for rollover/rollout and avoid that problem but you'll find it easier to import those images to your library and create your button using insert/new symbol/button and add the images from your library to the button timeline.

                  1 person found this helpful
                  • 6. Re: Problem on creating a button with as2
                    Ex0skelet0r Level 1

                    ok but how i can place this button where i want. i cant just drug it into a position, i have try it and it dissapear when i enter the website. the template loads everything dynamically.

                    if i create a button just like you are telling me how i can add it to the following target movie?

                     

                    logo2Load = function (path, targetMovie) {
                     targetMovie._alpha = 0;
                     var my_mcl:MovieClipLoader = new MovieClipLoader();
                     var mclListener:Object = new Object();
                     my_mcl.addListener(mclListener);
                     mclListener.onLoadInit = function() {
                     targetMovie._y = _root.XMLoptions_headerheight-Math.floor((XMLoptions_logoheight/2)+(XMLoptions_menuheight/2))-XMLoptions_logopaddingy;
                     Tweener.addTween(targetMovie,{_alpha:100, time:1, transition:"easeOutSine"});
                     targetMovie._x = Math.floor((Stage.width/2)+480-targetMovie._width-XMLoptions_logopaddingx);
                     

                     

                    If i add the rollover image to the library, can i change the path to show the image from the library? if yes how? i have try to add the image and use for path the name of the object (i have select export for actions cript) but it didnt work.

                     

                    About the thing you said about preloading, how i can preload just one image?

                    • 7. Re: Problem on creating a button with as2
                      Ex0skelet0r Level 1

                      i have a button named lang, how i can put it here:

                      _root.createEmptyMovieClip("logo2",_root.getNextHighestDepth());

                      • 8. Re: Problem on creating a button with as2
                        kglad Adobe Community Professional & MVP

                        drag your button to the stage where you want it positioned.  in the properties panel assign it an instance name, eg logo2Btn.

                         

                        click on the backstage to deselect your button and with a frame selected in the actions panel, use:

                         

                        logo2Btn.swapDepths(this.getNextHighestDepth());

                        • 9. Re: Problem on creating a button with as2
                          Ex0skelet0r Level 1

                          i cant place it where i want to be because every element of the site is loading dynamicaly. i have create the button and use this code

                           

                          _root.createEmptyMovieClip("logo2Btn",_root.getNextHighestDepth());

                          logo2Btn.swapDepths(this.getNextHighestDepth());

                          logo2Btn._x = Math.floor((Stage.width/2)+480-logo2Btn._width-XMLoptions_logopaddingx);

                           

                          im doing something wrong? im not sure if i have understand where youw ant me to put logo2Btn.swapDepths(this.getNextHighestDepth()).

                          • 10. Re: Problem on creating a button with as2
                            kglad Adobe Community Professional & MVP

                            1.  remove the swapDepths() method.

                             

                            2.  fix your assignment of your button's _x property.  what you have now makes no sense.  use the trace() function to see what you're doing.

                             

                            3.  assign your button's _y property unless you want that to be 0.

                            • 11. Re: Problem on creating a button with as2
                              Ex0skelet0r Level 1

                              I must doing something wrong, im using this:

                               

                               

                              _root.createEmptyMovieClip("logo2Btn",_root.getNextHighestDepth());

                              logo2Btn._x = 400;

                              logo2Btn._y = 10;

                               

                               

                              and every time i load the website i see the button for a second (in the possition i have drag n drop it in the stage, not the correct _x and _y) and it dissapear then (logo2Btn is the name of the button and i have select export to actionscript with the same name)

                               

                              i have also try this with no luck:

                              _root.attachmovie("logo2Btn", "logo2Btn1", _root.getNextHighestDepth());

                              logo2Btn1._x = 400;

                              logo2Btn1._y = 400;

                              • 12. Re: Problem on creating a button with as2
                                kglad Adobe Community Professional & MVP

                                try:

                                 

                                 

                                 

                                 

                                _root.createEmptyMovieClip("logo2Btn",1000000);

                                logo2Btn._x = 400;

                                logo2Btn._y = 10;

                                • 13. Re: Problem on creating a button with as2
                                  Ex0skelet0r Level 1

                                  it doesnt work either.

                                  i try to create btn.swf and load it and it works but i cant make the button clickable.

                                  in the action of main of the btn.fla i use this:

                                  btn.onRelease = function(){

                                  getURL("http://www.weareunited.com", "_blank");

                                  }but when i click noting happens, why?

                                  • 14. Re: Problem on creating a button with as2
                                    kglad-3jvbg7 Adobe Community Professional & MVP

                                    i know you think you need to create your button dynamically but you're incorrect.  so,  drag your button to the stage where you want it positioned.  in the properties panel assign it an instance name, eg logo2Btn.

                                     

                                    click on the backstage to deselect your button and with a frame selected in the actions panel, use:

                                     

                                    logo2Btn.swapDepths(1000000);

                                    • 15. Re: Problem on creating a button with as2
                                      Ex0skelet0r Level 1

                                      i done it and the button appears only for a second and then it dissapear, if i uploaded online will help you to understand what is going on?

                                      • 16. Re: Problem on creating a button with as2
                                        kglad Adobe Community Professional & MVP

                                        did you use the code i suggested swapping depths to 1000000?


                                        • 17. Re: Problem on creating a button with as2
                                          Ex0skelet0r Level 1

                                          yes, in action frame 1 the template has this code:

                                           

                                          stop();
                                          //
                                          //IMPORTS
                                          //
                                          import flash.display.*;
                                          import flash.events.*;
                                          import flash.filters.*;
                                          import caurina.transitions.Tweener;
                                          import caurina.transitions.properties.FilterShortcuts;
                                          FilterShortcuts.init();
                                          import caurina.transitions.properties.ColorShortcuts;
                                          ColorShortcuts.init();
                                          import SWFAddress;
                                          import SWFAddressEvent;
                                          //
                                          //STAGE SCALING AND ALIGNMENT
                                          //
                                          Stage.scaleMode = "noScale";
                                          Stage.align = "TL";
                                          //
                                          //VARIABLES
                                          //
                                          firstaddr = true;
                                          firstinit = true;
                                          loading = false;
                                          internalChange = false;
                                          bgimage = 0;
                                          bgpathvar = "";
                                          bgloaded = false;
                                          menuselected = "";
                                          submenuselected = "";
                                          addline = "";
                                          mp3toggle = false;
                                          moduleopen = false;
                                          moduleloaded = false;
                                          fs = false;
                                          videofs = false;
                                          volumevar = 100;
                                          pausevar = false;
                                          activepausevar = false;
                                          mloaded = 0;
                                          mtotal = 0;
                                          mloadstatus = 0;
                                          _global.modulexml = "";
                                          tilevar = false;
                                          tileData = "";
                                          //
                                          //INCLUDES
                                          //
                                          //XML MENU STRUCTURE AND OPTIONS LOADING
                                          
                                          #include "ext_xmlloading.as"
                                          

                                           

                                          i put your code before the include and it didnt work and i tr to put it inside the as file, after the command that creates and emptu movie clip for the logo with no luck

                                           

                                          for instance name i have give the same name,is it ok?

                                          • 18. Re: Problem on creating a button with as2
                                            kglad Adobe Community Professional & MVP

                                            what's the following show:

                                             

                                            var tl:MovieClip=this;

                                            logo2Btn.swapDepths(1000000);

                                            trace(logo2Btn+" "+this.getNextHighestDepth());

                                            setTimeout(traceF,5000);

                                            function traceF(){

                                            trace(tl.getNextHighestDepth())

                                            }

                                            • 19. Re: Problem on creating a button with as2
                                              Ex0skelet0r Level 1

                                              mm how i can see that? when i run the swf from adobe player i dont get any message

                                              • 20. Re: Problem on creating a button with as2
                                                kglad Adobe Community Professional & MVP

                                                how can you even debug your app??

                                                 

                                                test in flash:  control/test movie

                                                 

                                                copy the output and paste here.

                                                • 21. Re: Problem on creating a button with as2
                                                  Ex0skelet0r Level 1

                                                  sorry im noob in flash

                                                  when i compile the swf i dont get something on output but the swf must be put elshewhere for the site to work

                                                  i only get this

                                                   

                                                  Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/SOURCE FILES/xml/menu.xml'

                                                  Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/SOURCE FILES/xml/options.xml'

                                                  Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/SOURCE FILES/xml/music.xml'

                                                  Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/SOURCE FILES/xml/styles.css'

                                                  which is not an error, the xml files are somewhere else

                                                  • 22. Re: Problem on creating a button with as2
                                                    kglad Adobe Community Professional & MVP

                                                    save your fla to that "elshewhere" and retest.

                                                    • 23. Re: Problem on creating a button with as2
                                                      Ex0skelet0r Level 1

                                                      ok i get this

                                                       

                                                       

                                                      _level0.logo2Btn2 390129
                                                      Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/mp3/soundroll_circlesoflife.mp3'
                                                      Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/social/facebook_16.png'
                                                      Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/social/twitter_16.png'
                                                      Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/social/flickr_16.png'
                                                      Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/social/wordpress_16.png'
                                                      Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/social/rss_16.png'
                                                      Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/social/myspace_16.png'
                                                      Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/social/youtube_16.png'
                                                      390135
                                                      
                                                      • 24. Re: Problem on creating a button with as2
                                                        kglad Adobe Community Professional & MVP

                                                        try:

                                                         

                                                         

                                                        Button.prototype.swapDepths=MovieClip.prototype.swapDepths;

                                                         

                                                        var tl:MovieClip=this;

                                                        logo2Btn.swapDepths(1000000);

                                                        trace(logo2Btn+" "+this.getNextHighestDepth());

                                                        setTimeout(traceF,5000);

                                                        function traceF(){

                                                        trace(tl.getNextHighestDepth())

                                                        }

                                                        • 25. Re: Problem on creating a button with as2
                                                          Ex0skelet0r Level 1

                                                          it works, i can see the button

                                                          undefined 867626

                                                          Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/mp3/so undroll_circlesoflife.mp3'

                                                          Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/social /facebook_16.png'

                                                          Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/social /twitter_16.png'

                                                          Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/social /flickr_16.png'

                                                          Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/social /wordpress_16.png'

                                                          Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/social /rss_16.png'

                                                          Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/social /myspace_16.png'

                                                          Error opening URL 'file:///D|/Work/MarKat/epicure%2Dxml%2Dwebsite%2Dtemplate%2Dwith%2Ddeep%2Dlinking/social /youtube_16.png'

                                                          867632

                                                           

                                                          and this works too

                                                          logo2Btn2.onRelease = function()  {

                                                          getURL("test","_blank");

                                                          }

                                                           

                                                           

                                                          what was the problem?

                                                           

                                                          Now something else

                                                          I would like to add an effect when i rollover the button. right now in the menu it has this effect

                                                          Tweener.addTween(targetMovie,{_alpha:100, time:1, transition:"easeOutSine"});

                                                          how i can put it on the button rollover rollout also?

                                                          • 26. Re: Problem on creating a button with as2
                                                            kglad Adobe Community Professional & MVP

                                                            you were using a simplebutton instead of a movieclip button.

                                                             

                                                            for a rollover rollout effect, you can use:

                                                             

                                                            logo2Btn2._alpha = 80;

                                                            logo2Btn2.onRelease = function()  {

                                                            getURL("test","_blank");

                                                            }

                                                            logo2Btn2.onRollOver=function(){

                                                            Tweener.addTween(logo2Btn2,{_alpha:100, time:.5, });

                                                            }

                                                            logo2Btn2.onRollOut=function(){

                                                            Tweener.addTween(logo2Btn2,{_alpha:80, time:1, });

                                                            }

                                                             

                                                            p.s.  please mark this thread as answered, if you can.

                                                            1 person found this helpful
                                                            • 27. Re: Problem on creating a button with as2
                                                              Ex0skelet0r Level 1

                                                              may i ask something more? i want to do again the same but this time not to use a button but a external swf. what i have to change in this code:

                                                               

                                                              Button.prototype.swapDepths=MovieClip.prototype.swapDepths;

                                                               

                                                              var tl:MovieClip=this;

                                                              logo2Btn.swapDepths(1000000);

                                                              trace(logo2Btn+" "+this.getNextHighestDepth());

                                                              setTimeout(traceF,5000);

                                                              function traceF(){

                                                              trace(tl.getNextHighestDepth())

                                                              }

                                                              in order to load an external swf file? (if you can please also tell me the same for an internal swf)