7 Replies Latest reply on Jun 13, 2006 7:33 PM by kglad

    External Interface

    >Vee< Level 1
      Everything I find uses components to use the external API. Im not looking to use components. Thing is I cant get the simplest of things to work. Like the below. Ive changed the all code on the HTML page to "always", so that it can work locally. Nothing works. None of my old JS works in FLash 8, so im trying to get anything to work with external API. I need some help on getting started.
      //What Im using now:
      import flash.external.*;
      //call an alert
      alert_butn.clickHandler = function() {
      ExternalInterface.call("alert", alert_txt.text);
      };
      //what I used to do
      alert_butn.onRelease=function{
      getURL("javascript:alert('WORK!');");
      };
        • 1. Re: External Interface
          kglad Adobe Community Professional & MVP
          show your javascript. (and are you using a button component?)
          • 2. Re: External Interface
            >Vee< Level 1
            No, im not using a button component - do i have to?
            my js:
            function shake_xy(n) {
            if (self.moveBy) {
            for (i = 10; i > 0; i--) {
            for (j = n; j > 0; j--) {
            self.moveBy(0,i);
            self.moveBy(i,0);
            self.moveBy(0,-i);
            self.moveBy(-i,0);
            }
            }
            }
            }
            function shake_x(n) {
            if (self.moveBy) {
            for (i = 15; i > 0; i--) {
            for (j = n; j > 0; j--) {
            self.moveBy(i,0);
            self.moveBy(-i,0);
            }
            }
            }
            }
            function shake_y(n) {
            if (self.moveBy) {
            for (i = 20; i > 0; i--) {
            for (j = n; j > 0; j--) {
            self.moveBy(0,i);
            self.moveBy(0,-i);
            }
            }
            }
            }
            my AS:
            import flash.external.*;
            //call an alert
            my_btn.clickHandler = function() {
            ExternalInterface.call("shake_xy(2)");
            };
            • 3. Re: External Interface
              kglad Adobe Community Professional & MVP
              no, you don't need to use a button component. where's clickHandler defined?

              and how'd you go from a javascript function named alert ot one named shake? do your first and second messages have anything to do with each other?

              your first message's actionscript looks ok but i don't see any javascript. your 2nd message's javascript might be ok, but i don't see any javascript declaration and your actionscript is faulty: you should be using:

              • 4. Re: External Interface
                >Vee< Level 1
                kglad,

                In my first I was just trying to use a JS that was more simple as an explanation but then I switched to shake (i realized maybe I should just worry about communicating in one direction first!). Which now works great - thank you. I forgot to switch my event to onPress in my last post and put the JS declaration.
                What happens if you have several parameters to send back to the JS, such as when you open a new window with all the different attributes, such as I used to do below;
                • 5. Re: External Interface
                  kglad Adobe Community Professional & MVP
                  just list all the parameters separated by commas. read the flash help file under exteraninterface.call.
                  • 6. Re: External Interface
                    >Vee< Level 1
                    thanx, it worked.
                    • 7. Re: External Interface
                      kglad Adobe Community Professional & MVP
                      you're welcome.