8 Replies Latest reply on Apr 11, 2008 7:21 AM by w_danilo

    lingo-Java Script problem with new members

    w_danilo
      Hi, I'm new to Director, so this question could be very simple, but i can't find the answer in internet.
      I very like Flash and ActionScript and now i've started to learn Director.
      When I create a Sprite in a Cast- how can I (with JavaScript) copy this Sprite to the Stage as a new object with a new name?
      And the second question - Do you know any good sites, where are good articles, tutorials, examples, connected with scripting in Director?
      Than you very much :):)
        • 1. Re: lingo-Java Script problem with new members
          Level 7
          One thing here is that any items in the Cast are Members, not Sprites.
          Sprites do not exist in the Cast. The Cast is like Flash's Library.

          Sprites exist on the Stage or in the Score. The standard (non
          scripting) way to take a member and make a sprite on stage is to drag it
          there. If you want to script it, you have 2 options:

          1) puppetSprite
          2) makeScriptedSprite

          The 2nd option gives more control over the sprite. Check out the help
          file for syntax and examples
          • 2. lingo-Java Script problem with new members
            w_danilo Level 1
            Thank you!
            Could you answer one more question?
            When i create sprite like this:
            newsp1=channel(5).makeScriptedSprite(member("p1"), point(35, 70));
            how can I write to it dynamically function, that it (f.e.) should move in every frame about 1px right?
            (Can I write aaa.enterFrame=function (){...} ?)
            Thank you really very much :)
            • 3. Re: lingo-Java Script problem with new members
              Level 7
              I don't use Javascript syntax, so you will have to translate some of it,
              but here is how to do it in Lingo:

              You should see the sprite appear when you run that command, as long as
              the member you are using exists.

              You can add a script to the sprite by using the scriptInstanceList. If
              you have a parent script named "dynamicScript", then you would do
              something like this:

              newsp1=channel(5).makeScriptedSprite(member("p1"), point(35, 70))
              newspl.scriptInstanceList.add(script("dynamicScript").new())
              // add is the lingo method to add something to a list. You may need to
              adjust that to the JS version...push I think...

              --THIS IS THE PARENT SCRIPT NAMED DYNAMICSCRIPT IN LINGO--
              on new me
              return me
              end

              on enterFrame
              --do something
              end
              --END OF DYNAMICSCRIPT
              • 4. Re: lingo-Java Script problem with new members
                w_danilo Level 1
                Thank you :)
                I have unfortunately something wrong translated, because I've got no errors, but nothing happens. The script on the 1st Timeline frmae is:
                function exitFrame(me) {
                aaa=channel(5).makeScriptedSprite(member("p1"), point(0,1));
                aaa.locV=100;
                trace("t1") //this is traced
                aaa.scriptInstanceList.push(new script("dynamicScript"));
                trace("t2") //this is not traced
                }

                on the second frame:
                function exitFrame(me) {
                _movie.go(2);
                }

                and in the cast (name of this script is "dynamicScript"):
                function enterFrame()
                {
                trace("dsd");
                }

                I'm really thankful to you :)
                • 5. Re: lingo-Java Script problem with new members
                  Level 7
                  > aaa.scriptInstanceList.push(new script("dynamicScript"));

                  Try:
                  aaa.scriptInstanceList.append(new script("dynamicScript"));
                  • 6. Re: lingo-Java Script problem with new members
                    Level 7
                    Sorry. I don't know how to do it in JS. But your code does make a
                    scripted sprite appear (without any script)... as long as there is a
                    member named "p1".
                    • 7. Re: lingo-Java Script problem with new members
                      w_danilo Level 1
                      Thank you :) now it is working! :)
                      It schould be : append not push :)
                      • 8. Re: lingo-Java Script problem with new members
                        w_danilo Level 1
                        I have now another question, but it is connected with the previous prolem, so I would write it in this topic. :)

                        My "dynamicScript" is:
                        function enterFrame()
                        {
                        //this.locV+=1; //error
                        }

                        And I wont to move this object, to which is this script assigned, but I don't wont to use the name of that object. For example I wont to put on the stage several objects and each of them "append" to scriptInstanceList the same "dynamicScript" script and I want that, that each of these objects will move verticaly.
                        (In AS3 it would be event.currentTarget.y+=1; I hope you know what I mean :) )