Cloning

Where's my script gone?

Monday, May 21, 2007 by TwoWolves | Discussion: DesktopX

Hi,

I have a script which clones an object in a loop a number of times, everything is fine except the original object contains a small script which reacts to mouse-enter events. However the cloned objects do not inherit the script.

Any ideas how to do this or what I'm doing wrong?

Help much appreciated.

- Wolfie

SirSmiley
Reply #1 Monday, May 21, 2007 6:42 PM
Lot's of ideas but, then your question can be interpreted a number of ways.

If the script is in the object that is being cloned then it should be working unless the mouse-enter event is referencing another cloned object?

For example this script would work in the cloned object the same as the base object.

Code: vbscript
  1. 'Called on mouse over object
  2. Sub Object_OnMouseEnter
  3. Object.Left + 10
  4. Object.Top + 10
  5. End Sub


Edit: Oh great now the code tags are stripping formatting?
TwoWolves
Reply #2 Monday, May 21, 2007 7:42 PM
The OnMouseEnter only references that object.

So they are all independent objects that do not reference each other but are grouped (for movement) and have a third-party parent who does all the cloning.

Interestingly the object they are all cloned from reacts fine to the mouse events.


?
SirSmiley
Reply #3 Monday, May 21, 2007 10:53 PM
If the have a parent object then they aren't independent objects. Since you have them grouped make sure the child setting is no within the summary tab. That may do the trick.

It's hard to be specific without knowing much about the actual script. I just ran my bar chart script which clones a group (all are child objects) plus they reference & update a hidden object on mouse over and the mouse over event works fine. I'm using the onstatechange(state) because I'm referencing functions in the base script for different states.

So, this leads me to believe it is either specifically tied to your relationships or a scripting issue.
TwoWolves
Reply #4 Tuesday, May 22, 2007 5:25 PM
My Creation code is :
Code: vbscript
  1. Sub Object_OnScriptEnter
  2. DesktopX.Object("Grid").OnTop
  3. NumGrids = DesktopX.Object("MaskFrame").Height
  4. FirstX = DesktopX.Object("Grid").Left
  5. FisrtY = DesktopX.Object("Grid").Top
  6. For i = FirstY + 1 To NumGrids - 1
  7. nameObj = "Grid" & i
  8. DesktopX.Object("Grid").Clone nameObj, FirstX, FisrtY + i
  9. DesktopX.Object(nameObj).Parent = DesktopX.Object("Browser1")
  10. DesktopX.Object(nameObj).OnTop
  11. DesktopX.Object(nameObj).Group = "Window"
  12. Next
  13. End Sub

Each "Grid" Object has an OnMouseEnter block but only the original has the bespoke code, if I view the code for cloned objects they simply have a default script with empty OnScriptEnter and OnScriptExit sections.

Why don't they pick up the same script as the original object?

(Child setting is no)
SirSmiley
Reply #5 Tuesday, May 22, 2007 5:54 PM
If you copy & pasted that code directly then the answer lies within in the code. It appears it's possibly a simple spelling mistake "FisrtY"?

Edit:
If "Grid" has Parent & Group already set then you don't need these two lines.

DesktopX.Object(nameObj).Parent = DesktopX.Object("Browser1")
DesktopX.Object(nameObj).Group = "Window"

Plus, since you have set the ontop setting to the object being cloned you may not need this line either.

DesktopX.Object(nameObj).OnTop
TwoWolves
Reply #6 Wednesday, May 23, 2007 12:59 PM
You're right about the typo and not needing the parent and group being set in the script, however that hasn't resolved my problem.

The good news is that I have found a workaround.

By creating the clones in the outer-most object I can intercept the onmouseover messages using the *Ex form and determine the sender child object in an IF block.

Not as clean as I'd like but it works.

Thanks for your help though SirSmiley.
SirSmiley
Reply #7 Wednesday, May 23, 2007 1:14 PM
No problem. Glad you found a solution.

I have a nagging feeling that it's something simple that we're missing.

Please login to comment and/or vote for this skin.

Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:

  • Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
  • Access to a great community, with a massive database of many, many areas of interest.
  • Access to contests & subscription offers like exclusive emails.
  • It's simple, and FREE!



web-wc01