Jump to content

Recommended Posts

Hi,

 

I have added in a drag and drop function from a tutorial and it works well. The problem I am having is that I need my variable g_objName to be associated with dragobj. Has anyone any ideas?

 

function showObject (){
if (request.readyState == 4) {
var returned = request.responseText;
var splitResult = returned.split(" ");
var h = splitResult[0];
var w = splitResult[1];
h = h/5;
w = w/5;

cv = document.getElementById("canvas");
var newObject = document.createElement('div');
newObject.Class = g_objName;
newObject.id = "newObject";
newObject.innerHTML = g_objName;
newObject.style.height = h;
newObject.style.width = w;
newObject.onmousedown=function(){grab(this);}	
cv.appendChild(newObject);
}

function grab(context)
{
  document.onmousedown = falsefunc; // in NS this prevents cascading of events, thus disabling text selection
  dragobj = context;
  dragobj.style.zIndex = 10; // move it to the top
  document.onmousemove = drag;
  document.onmouseup = drop;
  grabx = mousex;
  graby = mousey;
  elex = orix = dragobj.offsetLeft;
  eley = oriy = dragobj.offsetTop;
  update();
}

Link to comment
https://forums.phpfreaks.com/topic/114243-solved-passing-a-variable/
Share on other sites

Hi,

 

I have added in a drag and drop function from a tutorial and it works well. The problem I am having is that I need my variable g_objName to be associated with dragobj. Has anyone any ideas?

 

function showObject (){
if (request.readyState == 4) {
var returned = request.responseText;
var splitResult = returned.split(" ");
var h = splitResult[0];
var w = splitResult[1];
h = h/5;
w = w/5;

cv = document.getElementById("canvas");
var newObject = document.createElement('div');
newObject.Class = g_objName;
newObject.id = "newObject";
newObject.innerHTML = g_objName;
newObject.style.height = h;
newObject.style.width = w;
newObject.onmousedown=function(){grab(this);}	
cv.appendChild(newObject);
}

function grab(context)
{
  document.onmousedown = falsefunc; // in NS this prevents cascading of events, thus disabling text selection
  dragobj = context;
  dragobj.style.zIndex = 10; // move it to the top
  document.onmousemove = drag;
  document.onmouseup = drop;
  grabx = mousex;
  graby = mousey;
  elex = orix = dragobj.offsetLeft;
  eley = oriy = dragobj.offsetTop;
  update();
}

 

Hmm... wouldn't g_objName already be available to you in grab()?  You're assigning the function to the onmousedown event handler of newObject.  Since g_objName is a property of newObject, it should be available inside of grab() as this.g_objName.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.