7 Replies Latest reply on Sep 28, 2006 10:44 PM by disco-logic

    Getting an actionscript to follow a symbol

    disco-logic
      some scripts, even those relating to an object, seem to need to go in the main timeline to work, and therefore dont exist in the symbol itself.

      Is there any way to get those scripts to follow the object around?

      Ill give an example of some code. Its for a cursor which makes the mouse disappear and a new one appear. Also it changes appearance over a certain object "boxthing" (in a bigger version I guess it would be a certain object type)

      Thanks for any assitance
        • 1. Re: Getting an actionscript to follow a symbol
          DazFaz Level 1
          I not entirely sure where you are coming from but I will pick up from "Is there any way to get those scripts to follow the object around?". You can alter, add, delete from the prototype of the object created. Then when that alteration is called from within the object, it will become unique to that object e.g.

          Button.prototype.onRelease = function(){
          trace(this._name);
          }

          so, you then create a button instance then put a simple on(release){} on to it. Then run your script and vwalla.

          This might well have missed the mark completely here but hey, what can you do. :D
          • 2. Re: Getting an actionscript to follow a symbol
            TimSymons Level 1
            The prototype method is good but you could also define a new class and attach it to a movieclip. It would "follow it around" like you want.

            class myclass extends MoiveClip {

            public function myclass() {
            // constructor
            }

            public function onRollOver() {
            cursor.gotoAndStop("cross");
            }

            public function onRollOut() {
            cursor.gotoAndStop("arrow");
            }

            }

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

            Then make sure you link this class to your boxthing movieclip by assigning this class to it.

            Tim
            • 3. Getting an actionscript to follow a symbol
              disco-logic Level 1
              thx faz and tim.

              I think the new class method is nearer to what I want. Especially as Im using actionscript to ease myself into a java and C++ way of thinking this seems closer to what Im after.

              Also tim, (or anyone), where do I put that bit of code. Does the class definition go in the code for the cursor object or is it defined elsewhere and somehow attached?
              • 4. Re: Getting an actionscript to follow a symbol
                TimSymons Level 1
                You define the class in an external .AS file. The file has to be named the exact of the class you are creating. Also, if you please the class file into a folder then you will have to make sure you inlcude that path in the name of the class when you define it. For example, if place the class AS file in a folder name com. Then your class definition would be:

                class com.ClassName extends MovieClip {

                // class code here

                }

                Take a look in the Help Docs under the following search area:

                ActionScript: Work with Objects and Classes


                Also, if you are completely new to this you will want to get a book on it too. The one by Colin Moock is pretty good. But there are others. Also, just to note. AS2 is similar to Java but AS3 is much closer so what you learn now in AS2 will be usful but there will be some AS2 hacks that you will have to un-learn in AS3.

                Good luck in your programming.

                Tim
                • 5. Re: Getting an actionscript to follow a symbol
                  disco-logic Level 1
                  thx tim.

                  What uses actionscript 3 btw?
                  • 6. Re: Getting an actionscript to follow a symbol
                    TimSymons Level 1
                    Flex 2 is the only commercial program but you can download an Alpha of Flash 9 (nothing spectacular about it except that you can write AS3 in it for practice). You will need your Flash 8 serial number to activate it and you can have both Flash 9 Alpha (remember it is an Alpha and all that it implies :-) and Flash 8 installed at the sametime.

                    You can get Flash 9 Alpha at labs.adobe.com. There is also a link the AS3 livedocs and a AS3 forum.

                    Tim
                    • 7. Re: Getting an actionscript to follow a symbol
                      disco-logic Level 1
                      hmm interesting. Might stick to flash 8 and AS2 for the time being seeing as Im only a newbie I dont want to confuse myself too hard (or rather I should say too much harder seeing as Im plenty confused as things are)