WebControlWrapper Cant SubClass

I have a custom WebControl but every time I try to subclass it in the project it throws an error.

In my case I have “WebSpriteButton”
And I’m trying to subclass “SpriteButtonAdmin” with super set to “WebSpriteButton”

Even before I add any additional properties or names it throws an error:
Location:
SpriteButtonAdmin.Name
Issue:
This item does not exist SpriteButtonAdmin

Two questions:

  1. Does SpriteButtonAdmin have a JavascriptNamespace constant?
  2. What is the scope of the JavascriptNamespace constant in WebSpriteButton?

[quote=132396:@Greg O’Lone]Two questions:

  1. Does SpriteButtonAdmin have a JavascriptNamespace constant?
  2. What is the scope of the JavascriptNamespace constant in WebSpriteButton?[/quote]
    The subclass does not have a JavascriptNamespace. I was hoping it would just inherit that from its parent. Is that not possible? That’s really inconvenient and annoying if not. The end user should be able to know next to nothing about the WebControlWrapper class and still be able to create their own subclasses of these controls. (right?) And its not like the error message is even remotely helpful…

There’s a reason for this. If a user is creating an instance of your control there’s no need for a JavascriptNamespace.

So what was your answer to question #2?

The user isn’t creating an instance - the user is creating a subclass in their project. If I deploy my control and they want to subclass some implementation of it, they shouldn’t be required to know anything about the WebControlWrapper or that they need to add a random property called Javascript namespace. The namespace should either inherent from the parent or randomly generate a GUID namespace.

Adding a namespace to the subclass fixed the problem, but the error message did absolutely nothing to make this clear. In addition to this goes against Xojo’s core principles of being beginner-friendly. If a user subclasses a custom control can it add a “.” to the javascript namespace on compile-time if they don’t provide one?

Both the custom control and its subclass are public. I did notice something weird though. When I had my control in a folder called “UI” it appeared public, but when I had next into “UI->Spritesheet” it appeared yellow automatically which I assume means it was protected. Any idea why this would be happening?

That’s not necessary. Just make sure that the JavascriptNamespace constant is Public on the controls that you want the users to subclass. If its available, they won’t need to add their own.

Question # 2 was: What is the scope of the JavascriptNamespace constant in WebSpriteButton?

The reason I asked this was I had a hunch that it was Private. I was not looking for the scope of the class itself, just the constant.

If you had this item inside a Module at one point, the scope may have been set. When you drag it out, the scope info doesn’t get stripped.

[quote=132532:@Greg O’Lone]That’s not necessary. Just make sure that the JavascriptNamespace constant is Public on the controls that you want the users to subclass. If its available, they won’t need to add their own.

Question # 2 was: What is the scope of the JavascriptNamespace constant in WebSpriteButton?

The reason I asked this was I had a hunch that it was Private. I was not looking for the scope of the class itself, just the constant.

If you had this item inside a Module at one point, the scope may have been set. When you drag it out, the scope info doesn’t get stripped.[/quote]

Yeah it was definitely Private! :slight_smile: That makes sense. Thanks for your help Greg. Can we still improve that error message though?
Also the control was never in a Module so I’m not sure why changing what nested folder its in would change its scope… weird.

Please file a bug report so I don’t forget about it.

<https://xojo.com/issue/35546>

already there: <https://xojo.com/issue/34741> and maybe <https://xojo.com/issue/23666>
Merge request sent