3 Replies Latest reply on Feb 27, 2007 12:32 PM by Newsgroup_User

    Retrieve dynamic movie clip variable

    Mwholey
      Apologies for what may be a simple question, but I am new to Actionscript.

      I have an SWF file that contains a series of movie clips that are named as a result of a loop through an associated XML file as below:

      _root.pageHolder.page[imageId].imageId = imageId;


      the "clips" are associated with positions on the display. when one is clicked I'd like to reveal the imageId associated with that MC. This info is then passed to a Javascript function. As it stands now, I have the following code which returns only the last node in the XML to the javascript, not the clicked item's imageId:

      ExternalInterface.call("addToCart",_root.pageHolder.page[imageId].imageID);

      Is there an obvious answer that I am missing?

      Much appreciated.
      MW


        • 1. Re: Retrieve dynamic movie clip variable
          Level 7
          The problem is that the imageId becomes that of the last nodes by the time
          you click on any of the buttons... when you assign the onPress (?) it
          doesn't not memorize the value of imageId at the time. So, when it is
          clicked, it will be the last value of it, which would be the last nodes. To
          remedy, make sure the clip with the onPress *knows* it's associated imageId
          (which you have done halfway with "_root.pageHolder.page[imageId].imageId =
          imageId;").
          If _root.pageHolder.page[imageId] is the clip that is being clicked you
          could simply have something like:

          _root.pageHolder.page[imageId].onPress = function(){
          ExternalInterface.call("addToCart",this.imageId);
          }

          If it is some other clip, make sure that you assign it a property with the
          imageId, and then use this.imageId in the event handler.

          @macromedia.com> wrote in message news:ervm9h$fui$1@forums.macromedia.com...
          > Apologies for what may be a simple question, but I am new to Actionscript.
          >
          > I have an SWF file that contains a series of movie clips that are named as
          > a
          > result of a loop through an associated XML file as below:
          >
          > _root.pageHolder.page[imageId].imageId = imageId;
          >
          >
          > the "clips" are associated with positions on the display. when one is
          > clicked
          > I'd like to reveal the imageId associated with that MC. This info is then
          > passed to a Javascript function. As it stands now, I have the following
          > code
          > which returns only the last node in the XML to the javascript, not the
          > clicked
          > item's imageId:
          >
          > ExternalInterface.call("addToCart",_root.pageHolder.page[imageId].imageID);
          >
          > Is there an obvious answer that I am missing?
          >
          > Much appreciated.
          > MW
          >
          >
          >
          >


          • 2. Re: Retrieve dynamic movie clip variable
            Mwholey Level 1
            Thanks for the input. I knew that was what I was shooting for, I was just having trouble retrieving the variable from the movieclip associated with the onPress. I ended up establishing a global variable that was set depending on the click. From the second movieclip I just referenced the global.
            Thanks again,
            MW
            • 3. Re: Retrieve dynamic movie clip variable
              Level 7
              You're welcome.

              "Mwholey" <webforumsuser@macromedia.com> wrote in message
              news:es22nk$erg$1@forums.macromedia.com...
              > Thanks for the input. I knew that was what I was shooting for, I was just
              > having trouble retrieving the variable from the movieclip associated with
              > the
              > onPress. I ended up establishing a global variable that was set depending
              > on
              > the click. From the second movieclip I just referenced the global.
              > Thanks again,
              > MW
              >
              >