6 Replies Latest reply on Dec 29, 2006 3:00 AM by Newsgroup_User

    Easy Function

    Obster
      I know this should be an easy one but ive been busting my butt looking for a solution.
      I am trying to pull an external jpg file into a new window using different buttons. I know there is a way to assign a function to each button for just the file path then I dont have to copy and paste all the code to open up the window.
      I created the function changepic() you can see where i want to insert the path in "test picture 1". "test picture 2" shows the path without calling the function. I have the button code at the bottom. Any assistance would be greatly appreciated.
      Thanks for your time. I know im doing something stupid.

      import mx.managers.PopUpManager;
      import mx.containers.Window;
      function changePic() {

      }

      var issueLocation:Boolean = true;
      function toggleCity() {
      var currentArea:Number;
      if (issueLocation) {
      currentArea = 0;
      issueLocation = false;
      var my_win = mx.managers.PopUpManager.createPopUp(_root,
      mx.containers.Window, true, {title:"test picture 1",
      closeButton:true,contentPath:changePic()});
      my_win.setSize (800,600);
      var winListener:Object = new Object();
      winListener.click = function() {
      my_win.deletePopUp();
      };
      my_win.addEventListener("click", winListener);

      } else {
      currentArea = 1;
      issueLocation = true;
      var my_win = mx.managers.PopUpManager.createPopUp(_root,
      mx.containers.Window, true, {title:"test picture 2",
      closeButton:true,contentPath:"pics/test.jpg"});
      my_win.setSize (800,600);
      var winListener:Object = new Object();
      winListener.click = function() {
      my_win.deletePopUp();
      };
      my_win.addEventListener("click", winListener);



      // location for future code to calculate Payoff from mySQL
      }

      }

      button_btn.onPress = function() {
      toggleCity();
      changePic("pics/test.jpg");

      }
        • 1. Re: Easy Function
          Level 7
          Hi,
          This way won't have effect.. I made two modifications, try this...

          Obster wrote:
          > [...]
          > import mx.managers.PopUpManager;
          > import mx.containers.Window;
          >
          > var issueLocation:Boolean = true;
          > function toggleCity(value:String) { //I modified here
          > var currentArea:Number;
          > if (issueLocation) {
          > currentArea = 0;
          > issueLocation = false;
          > var my_win = mx.managers.PopUpManager.createPopUp(_root,
          > mx.containers.Window, true, {title:"test picture 1",
          > closeButton:true,contentPath:value:String});
          > my_win.setSize (800,600);
          > var winListener:Object = new Object();
          > winListener.click = function() {
          > my_win.deletePopUp();
          > };
          > my_win.addEventListener("click", winListener);
          >
          > } else {
          > currentArea = 1;
          > issueLocation = true;
          > var my_win = mx.managers.PopUpManager.createPopUp(_root,
          > mx.containers.Window, true, {title:"test picture 2",
          > closeButton:true,contentPath:"pics/test.jpg"});
          > my_win.setSize (800,600);
          > var winListener:Object = new Object();
          > winListener.click = function() {
          > my_win.deletePopUp();
          > };
          > my_win.addEventListener("click", winListener);
          >
          >
          >
          > // location for future code to calculate Payoff from mySQL
          > }
          >
          > }
          >
          > button_btn.onPress = function() {
          > toggleCity("pics/test.jpg"); //I modified here
          > }
          >


          --
          Regards,
          Erick Souza | ericksouza.com
          • 2. Re: Easy Function
            Level 7
            I sent this line with a mistake, remove it ": String"

            [...]
            var my_win = mx.managers.PopUpManager.createPopUp(_root,
            mx.containers.Window, true, {title:"test picture 1",
            closeButton:true,contentPath:value:String});
            [...]


            --
            Regards,
            Erick Souza | ericksouza.com
            • 3. Easy Function
              Peter Lorent Level 2
              Try the following, attached code.
              And change the contentPath to image:
              ,contentPath:image});

              • 4. Re: Easy Function
                Level 7
                LuigiL, I believe that the correct as follows.


                function changePic(path:String):String{
                return path;
                }


                --
                Regards,
                Erick Souza | ericksouza.com
                • 5. Re: Easy Function
                  Peter Lorent Level 2
                  No. The script uses a simple timeline var 'image' which is set by changePic().
                  As always there are several solutions and I was just following the path the OP took with his approach.
                  • 6. Re: Easy Function
                    Level 7
                    I understand. You didn't indicate the alteration in the toggleCity
                    function and I confused his objective.


                    --
                    Regards,
                    Erick Souza | ericksouza.com