Solved

Javascript: VML and onmouseover and onmouseout event howto?

Posted on 2007-12-01
11
1,519 Views
Last Modified: 2013-11-19
Hi,

   I would like to know how to use on a VML element the fonction onmouseover. My element is dynamic.

Here is a piece of the code, there is only this part missing to make it work. I will use the onmouseover
on the rect element and when it fire I will assign a variable an ID, the one of the group element.
This will let me drag the whole group, the whole drag and drop should be working it's only the onmouseover that I don't figure out. For the moment I have remove it from the code.


var vm = document.createElement("v:group");
      vm.setAttribute("id", this.Name);
      vm.style.position = "absolute";
      vm.style.width = this.W + "px";
      vm.style.height = this.H + "px";
      vm.style.left = this.X + "px";
      vm.style.top = this.Y + "px";
      vm.style.zIndex = 0
      vm.setAttribute("coordsize", this.W + " " + this.H);
 
      var rect = document.createElement("v:rect");
      rect.setAttribute("id", this.Name + "_rect1")
      vm.style.position = "relative";
      rect.style.width = this.W  + "px";
      rect.style.height = this.H + "px";
      rect.style.zIndex = 1
      rect.setAttribute("fillcolor", "black");
      vm.appendChild(rect);
      document.body.appendChild(vm);
      vm = null
      rect = null

Open in new window

0
Comment
Question by:Dogofwars
  • 6
  • 5
11 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20391071
You mean

vm.onmouseover=function() {
  window.status = this.id;
  return true;
}

vm.onmouseout=function() {
  window.status = '';
  return true;
}

(Simple example).


0
 

Author Comment

by:Dogofwars
ID: 20391788
Almost, the onmouseover most trigger only another function to give it's id to a master object like the following

Thank you by the way for your assistance.
function MasterObject()
{
   this.ActiveObject
}
 
var MO =  new MasterObject
 
vm.onmouseover = MO.ActiveObject = vm.id or 
rect.onmouseover = MO.ActiveObject = vm.id

Open in new window

0
 

Author Comment

by:Dogofwars
ID: 20391798
oups. I mean var MO =  new MasterObject()
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:Dogofwars
ID: 20393243
This seem to work but I cannot reference back the variable to this.Name for instance that is within the object. I presume it has no way to do so with variable since it execute the code outside the scope of the object. Would it be possible to do the following.
vm.onmouseover = this.Owner.Name + ".OnMouseOver('" + this.Name + "')"
 
When it fire the event it give this
   
    MasterObjectName.OnMouseOver('TestObject')

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20394536
If you replace an event handler you need to assign a function or run a function that returns a function

This is not valid javascript

this.Owner.Name + ".OnMouseOver('" + this.Name + "')"
0
 

Author Comment

by:Dogofwars
ID: 20396543
Do you have some kind of example to overcome this problem
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20398168
I gave an example. I do not understand the string
this.Owner.Name + ".OnMouseOver('" + this.Name + "')"

at all
0
 

Author Comment

by:Dogofwars
ID: 20398389
This get transform to a text string that will later be a regular javscript instruction

Like

this.Owner.Name + ".OnMouseOver('" + this.Name + "')"

become

aObject.OnMouseOver('SomeObjectID')

Anyhow the problem is that I need the example you provide to carry the reference of the object itself because for instance this.id is not reference to the object in question but just the general pool like the main variable. It's really a pain though it kinda work just the way you provided but with a lot of flaw, I have to use extra windows event and some general variable which is more difficult to track every object.

vm.onmouseover=function() {
  window.status = this.id;
  return true;
}



0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20401289
You mean



vm.onmouseover=function() {
  someOtherObject.onmouseover()
}


OnMouseOver is not a valid reference ot a mousover event of an object

Perhaps you mean
vm.onmouseover=function() {
  someOtherObject.SomeSpecialFunctionYouWrote('someId')
}

0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 500 total points
ID: 20401295
You can also do this:

vm.setAttribute("myParentId", "X1234");
vm.setAttribute("myParameter", "Z5678");


Perhaps you mean
vm.onmouseover=function() {
  var parentId = this.getAttribute('myParentId');
  var parameter = this.getAttribute('myParameter')
  someFunction(document.getElementById(parentId),parameter)
}

0
 

Author Closing Comment

by:Dogofwars
ID: 31412169
That is good compromise if at all a compromise, thank you very much that will be really useful for my drag and drop function with VML :)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now