2 Replies Latest reply on Aug 14, 2006 8:54 AM by Newsgroup_User

    _global refer to instance

    Level 7
      I am having trouble using a global variable to refer to an instance, is
      this possible? Here is my situation :

      I have a series of moviclip buttons with the following actionscript :
      this.onRelease = function(){
      _root.mcloader.displayed.gotoAndStop(1);
      _global.displayed = "redballs";
      }

      basically when a button is pressed I want it to tell the movieclip
      "_root.mcloader.displayed" to go to frame1, where "displayed" represents
      an everchanging global variable. Then after that it resets the global
      variable "displayed". The code is setting the variable fine, but I can't
      get the :

      to work. Any suggestions?

      Thanks
      Tim
        • 1. Re: _global refer to instance
          Level 7
          Tim,

          > I have a series of moviclip buttons with the following
          > actionscript :
          > this.onRelease = function(){
          > _root.mcloader.displayed.gotoAndStop(1);
          > _global.displayed = "redballs";
          > }

          Okay.

          > basically when a button is pressed I want it to tell the
          > movieclip "_root.mcloader.displayed" to go to frame1,
          > where "displayed" represents an everchanging global
          > variable.

          It looks like you're having trouble because the value of _global
          displayed is a string, rather than a movie clip.

          > >The code is setting the variable fine, but I can't
          > get the :
          >
          > to work. Any suggestions?

          I believe part of your code is missing -- happens often in these forums;
          not necessarily your fault. :) I'lll take a guess a presume that you're
          later visiting _global.displayed as your movie clip path and are suprised
          when you can't, fore example, do something like this:

          _global.displayed.gotoAndPlay("somewhere else");

          ... and again, the reason for this is that the value of displayed is a
          string -- and the String class does not feature a gotoAndPlay() method, so
          nothing happens. What you need is for that global property to refer to a
          movie clip instance.

          You can either set the reference yourself ...

          this.onRelease = function(){
          _root.mcloader.displayed.gotoAndStop(1);
          _global.displayed = _root.redballs;
          // or whatever the path is
          }

          ... in which case, it may not make sense to even use a _global variable,
          since the reference is so straightforward.

          OR, you can use the eval() function or array access operators, as
          described here.

          http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically


          David Stiller
          Adobe Community Expert
          Dev blog, http://www.quip.net/blog/
          "Luck is the residue of good design."


          • 2. Re: _global refer to instance
            Level 7
            GREAT!

            Thanks for clarifying for me!

            Tim

            In article <ebpu91$hgs$1@forums.macromedia.com>, "David Stiller"
            <stiller-NO-SPAM-@quip.net> wrote:

            > Tim,
            >
            > > I have a series of moviclip buttons with the following
            > > actionscript :
            > > this.onRelease = function(){
            > > _root.mcloader.displayed.gotoAndStop(1);
            > > _global.displayed = "redballs";
            > > }
            >
            > Okay.
            >
            > > basically when a button is pressed I want it to tell the
            > > movieclip "_root.mcloader.displayed" to go to frame1,
            > > where "displayed" represents an everchanging global
            > > variable.
            >
            > It looks like you're having trouble because the value of _global
            > displayed is a string, rather than a movie clip.
            >
            > > >The code is setting the variable fine, but I can't
            > > get the :
            > >
            > > to work. Any suggestions?
            >
            > I believe part of your code is missing -- happens often in these forums;
            > not necessarily your fault. :) I'lll take a guess a presume that you're
            > later visiting _global.displayed as your movie clip path and are suprised
            > when you can't, fore example, do something like this:
            >
            > _global.displayed.gotoAndPlay("somewhere else");
            >
            > ... and again, the reason for this is that the value of displayed is a
            > string -- and the String class does not feature a gotoAndPlay() method, so
            > nothing happens. What you need is for that global property to refer to a
            > movie clip instance.
            >
            > You can either set the reference yourself ...
            >
            > this.onRelease = function(){
            > _root.mcloader.displayed.gotoAndStop(1);
            > _global.displayed = _root.redballs;
            > // or whatever the path is
            > }
            >
            > ... in which case, it may not make sense to even use a _global variable,
            > since the reference is so straightforward.
            >
            > OR, you can use the eval() function or array access operators, as
            > described here.
            >
            >
            http://www.quip.net/blog/2006/flash/actionscript-20/reference-objects-dynamically
            >
            >
            > David Stiller
            > Adobe Community Expert
            > Dev blog, http://www.quip.net/blog/
            > "Luck is the residue of good design."