"EnTerr" wrote:
You mean if i want to "extend" an existing component?! I don't want to do that... why would i?
I'd expect at the very least you'd want to extend a Scene node, but if not, you still need a way to hook into it's context, and there's no way to do that without extending it. Additionally, if you want to take advantage of the multi-threading capabilities of SceneGraph, then you'll have to extend the Task node. It can't be used generically, because the "functionName" has to be the name of a function that is defined inside the Task's context, which again, can only be established by specifying the <script/> that belongs to that Task. Note that "functionName" is a string, not a function reference.
"EnTerr" wrote:
... specific init() and onKeyEvent() functions. Note that those are not methods on the component itself, but rather intrinsic event handler functions.
tOmato, tomAto - it's a question of what you name them. Event handlers which are functions that get invoked by magic-name... call them methods or not, it would be best they get accessible name slots in the node, so they can be assigned to or called directly... no?
Not exactly. At least in the case of onKeyEvent, it doesn't belong to the node. It's an event handler that is registered to observe some global event that isn't exposed elsewhere. Its presence in the component's code is only to establish context within that node's global AA, which you do not have access to outside of that component. The key event walks up the focus chain until one of the components' onKeyEvent listeners says it has handled the event, so you'll need code running somewhere in the context of one of those components if you want to respond to key events.
So, modifying my code above slightly, I still believe, at the very least, you'd need this XML:
<?xml version="1.0" encoding="utf-8" ?>
<component name="myScene" extends="Scene">
<script type="text/brightscript" uri="pkg:/components/myScene.brs" />
</component>
You could then add an onKeyEvent function to myScene.brs that sets a field on the scene to raise it to the BrightScript thread. Then, in the BrightScript thread, you'd need to set a second field on the Scene, so it knows whether the key press was handled or not.
Honestly, I don't think there's any way you'd be able to create and control a SceneGraph application entirely from the main BrightScript thread without at least some XML. Even if you could, I can't imagine you'd really want to, as every operation would block the UI. If you want to do that, then I'd say it's better to stick with the 2D API.
My Channels: http://roku.permanence.com - Twitter: @TheEndlessDev
Instant Watch Browser (NetflixIWB), Aquarium Screensaver (AQUARIUM), Clever Clocks Screensaver (CLEVERCLOCKS), iTunes Podcasts (ITPC), My Channels (MYCHANNELS)