Loading ...
Sorry, an error occurred while loading the content.

Re: [ydn-javascript] Re: Using array notation to create drag/drop objects

Expand Messages
  • Adam Moore
    ... Make sure you have declared i : for (var i=1; i
    Message 1 of 4 , Apr 30, 2007
    • 0 Attachment
      On Sun, Apr 29, 2007 at 12:28:14AM -0000, rocketeerbkw wrote:
      > I thought that by giving my actual code, I would make more sense:
      >
      > for (i = 1; i <= 3; i++) {
      > mnFdrg[i] = new YAHOO.util.DD("mnFdrg" + i, "Alias1", {isTarget:false});
      > }

      Make sure you have declared "i":

      for (var i=1; i<=3; i=i+1)
      mnFdrg[i] = new YAHOO.util.DD("mnFdrg" + i, "Alias1", {isTarget:false});
      }

      > In a seperate file I have this:
      > for (i = 1; i <= 3; i++) {
      > mnFdrg[i].startDrag = function (X, Y)
      > {
      > //ttFdrg[i].hide();
      > mnFdrg[i].addToGroup("Alias2");
      > mnFdrg[i].addToGroup("Alias3");
      > mnFdrg[i].addToGroup("Alias4");
      > mnFdrg[i].removeFromGroup("Alias1");
      > getObject('status').innerHTML = this.id + " drag started";
      > return true;
      > }
      > }

      Don't try to use the reference to the array item in the body of the
      startDrag function. Use "this" instead:

      for (var i=1; i<=3; i=i+1) {
      mnFdrg[i].startDrag = function (x, y) {
      this.addToGroup("Alias2");
      this.addToGroup("Alias3");
      this.addToGroup("Alias4");
      this.removeFromGroup("Alias1");
      YAHOO.util.Dom.get('status').innerHTML = this.id + " drag started";
      }
      }


      -Adam
    • rocketeerbkw
      ... started ; ... Thank you very much, that definitely helps solve that problem. In the code I posted i had //ttFdrg[i].hide(); The reason it s commented out
      Message 2 of 4 , Apr 30, 2007
      • 0 Attachment
        --- In ydn-javascript@yahoogroups.com, Adam Moore <adamoore@...> wrote:
        > Don't try to use the reference to the array item in the body of the
        > startDrag function. Use "this" instead:
        >
        > for (var i=1; i<=3; i=i+1) {
        > mnFdrg[i].startDrag = function (x, y) {
        > this.addToGroup("Alias2");
        > this.addToGroup("Alias3");
        > this.addToGroup("Alias4");
        > this.removeFromGroup("Alias1");
        > YAHOO.util.Dom.get('status').innerHTML = this.id + " drag
        started";
        > }
        > }
        >
        >
        > -Adam
        >

        Thank you very much, that definitely helps solve that problem. In the
        code I posted i had //ttFdrg[i].hide();
        The reason it's commented out was because it was giving me the same error.
        The reason I'm calling that is because it is a reference to a tooltip,
        and i want it to go away whenever someone starts dragging.
        ttFdrg[1] = new YAHOO.widget.Tooltip("ttFdrg1", {context:"mnFdrg1",
        text:"<img src=\"images/thumbnails/thumb1.gif\" />", showDelay:200});

        if I can't use "this" how can I reference that?
      Your message has been successfully submitted and would be delivered to recipients shortly.