Storyboard and Listeners question (confused a lot)

I’ve just started working with storyboard and never before used director class.
I read all the documentation and blog posts about it and started developing with it.
But i have a huge question and i can’t find the answer.
For what i understood, event listeners must go in the enterScene function of my Scene.
I believe there are some rules i’m missing about it.

I declared a local function inside createScene.
If i want to call it inside enterScene (as i believe it must be) using Runtime:addEventListener(“enterFrame”, myFunction), it doesn’t work.
So i tried turning the function into a global one.
From there on, it works fine.
Problem is, i’m having a bad feeling about this, don’t feel like having to declare global functions.
What’s more, checking the storyboard sample code my idea was confirmed, as functions are declared locally.

So as you can see, i’m missing something BIG about this.
Please, can anybody help me?
Thanks! [import]uid: 105206 topic_id: 20509 reply_id: 320509[/import]

You are running into an issue called “Scope”.

Please read these two posts, and then come back with additional questions:

http://blog.anscamobile.com/2011/09/tutorial-scopes-for-functions/

http://omnigeek.robmiracle.com/2011/10/14/understanding-scope-for-beginning-programmers/

[import]uid: 19626 topic_id: 20509 reply_id: 80416[/import]

declare or forward-declare your local function outside createScene().
[import]uid: 33608 topic_id: 20509 reply_id: 80442[/import]

Functions you want available to both createScene and enterScene (or any of the others) need to be declared outside of createScene or enterScene like right below this block of code:

[lua]local storyboard = require( “storyboard” )
local scene = storyboard.newScene()


– BEGINNING OF YOUR IMPLEMENTATION

– NOTE: Code outside of listener functions (below) will only be executed once,
– unless storyboard.removeScene() is called.


** your code and variables here that you want available to all the story board eventListeners[/lua]
[import]uid: 19626 topic_id: 20509 reply_id: 80456[/import]

great thanks! i knew it was something about the scope.
I don’t know why i understood that i could declare all functions in createScene and just call them in enterScene (doesn’t really make sense at all lol)
Awsome support guys! [import]uid: 105206 topic_id: 20509 reply_id: 80593[/import]