3 Replies Latest reply on Nov 28, 2009 6:09 PM by Loveanie

    Actionscript in particular layer only

    ayusuits

      The code below is the one I pasted on Layer 1. But unfortunately, when I go to Layer 16, or any other layer, this script is still functioning.

       

      Code:
      import flash.external.*;
      
      var methodName:String = "setKey";
      var instance:Object = null;
      var method:Function = recieveTextFromHtml;
      var wasSuccessful:Boolean = ExternalInterface.addCallback(methodName, instance, method);
      
      function recieveTextFromHtml(t) {
           if (t=='f2')   { 
                ExternalInterface.call("command('listen')"); 
                gotoAndStop("Blisten");
           }
           if (t=='enter'){ 
                ExternalInterface.call("command('popup',1)"); 
                gotoAndStop("F");
           }
      }
      
      myListener = new Object();
      myListener.onKeyDown = function() {
           if (Key.getCode() == 113)  {
                getURL("javascript:command('listen')"); 
                gotoAndStop("Blisten");
           }
      };
      Key.addListener(myListener);
      Is there a way to block it? It should only work in layer 1.

       


      I think the myListener is the suspect... grrr, it's running even if myListener button is only in 1st frame. RemoveListener is not working???

        • 1. Re: Actionscript in particular layer only
          Rothrock Level 5

          By "layer one" do you mean frame 1?

           

          Code is assigned in frames and knows nothing about layers. Layers are just tools to help layout your work in the authoring environment. In fact when you publish to the swf Flash uses the layers to decide how things are stacked from back to front and then it deletes all the layers from the final output.

           

          You also say something about "RemoveListener" not working. But I don't see where you've used that. Additionally be sure that you have it as removeListener — capitalization matters.

           

          Additionally if you are looping your timeline you need to be careful because you can start adding the same listener over and over and then you can get multiple function calls for each event.

          • 2. Re: Actionscript in particular layer only
            Gurflob

            Your code is probably "pinned" that means no matter where you go in your document you can access it. In your actions window click the safetypin in the bottom to unpin it.

            • 3. Re: Actionscript in particular layer only
              Loveanie Level 1

              I never used ExternalInterface with AS 2.0, but I agree that you should:

              1- probably add a stop(); action after the import statement (unless you do it elsewhere, since we don't have code on other frames...);

              2- add "Key.removeListener(myListener);" at the end of the if statement:

              myListener.onKeyDown = function() {
                   if (Key.getCode() == 113)  {
                        getURL("javascript:command('listen')");
                        gotoAndStop("Blisten");
                        Key.removeListener(myListener);
                   }
              };

               

              That way, once we have pressed the key, we won't be able to do it again (unless some code brings us back at frame one).

               

              For the other response you had...: Pinning don't change anything to the "scope" of the code; it only allows you to see the code from different places just by clicking on a tab...