-
Mental Ward Patient
Functions on different Layers.
I've just started working on my engine again, but it seems i cant call functions from different layers, which is VERY annoying considering i like to organize my code on different layers. Is this true or am i just doing something wrong?
-
smile for the camera!
well, to call functions from another layer, it has to be a layer that is on top of the layer thats calling it, otherwise the function doesnt exist yet.
My site
The Current Project is RoboRace.
Screens Public Beta Coming Soon!
-
Mental Ward Patient
-
Script kiddie
I thought it depended on how you're calling the function.
function myFunction() {
}
Should work fine no matter where it's declared, but
myFunction = function() {
};
Will only exist once the script is run... right?
-
^^ they'll work the same, but are used for two different things
myFunction = function() is used for methods or prototyping
var myObj = new Object
myObj.functionName = function ( )
-
smile for the camera!
i just have experience with functions doing this.
My site
The Current Project is RoboRace.
Screens Public Beta Coming Soon!
-
Heli Attack!
Functions are 'created' when the script is executed.
When the playhead gets to a frame, it executes the code from the top frame down, so you can call functions on a lower frame, but not the opposite.
However, in my opinion, the correct way to do it is to have the playhead move over your function declerations, and then move on to your game logic.
For my games, I go to an 'init' frame which executes and creates all my functions, then I go to the menu. After that I never have a need to touch the init frame again, as from then on, I can call the functions from anywhere.
-
leight.com.au
iopred, wouldn't that be faster also? Because during the actual game, the flash player doesn't have to run through the function code again, unless it is being called up?
- leighton
-
Heli Attack!
-
The difference between the two function declarations of :-
code:
function myFunction() {
}
and
code:
myFunction = function() {
};
is that the latter can not be executed by a statement before it is created i.e. if some line contains a call to it before its declaration in the same frame for example, then it won't be executed, but the previous one does.
First type this in your first frame and run it:-
code:
scan();
function scan()
{
trace("called");
}
then try this:-
code:
scan();
scan = function()
{
trace("called");
}
you can see the difference.
edit:
iopred, wouldn't that be faster also? Because during the actual game, the flash player doesn't have to run through the function code again, unless it is being called up?
- leighton
I don't think the flash player runs through the function code untill it is evoked, so it should'nt make much or any difference
Last edited by adit_ya_sharma; 05-23-2005 at 12:32 AM.
-Aditya
-
Heli Attack!
I think leight was talking about flash actually creating the objects to hold the functions, if every frame your redefining the functions, it should be slower than defining it only once.
-
yeah ofcourse
edit: I was wondering though, will this be feasable, I have many mc's in my side scrolling game which have the same code running on them individually with one 'onEnterFrame' for each one. Now, since the code in all of them is the same, will doing something like this will make it any faster
1) I make the whole code in a function body on the main timeline like:-
code:
checky = function()
{
the code here....
}
and in all the mc's i can write this:-
code:
onEnterFrame = function()
{
_root.checky();
}
???
Last edited by adit_ya_sharma; 05-23-2005 at 01:31 AM.
-Aditya
-
Heli Attack!
It will call the function, but you will find it will not work as you think it will.
For it to work as you hope, you should do something as such:
code:
onClipEvent(load){
this.frame = _root.frame;
}
onClipEvent(enterFrame){
this.frame();
}
or
code:
this.frame = _root.frame;
this.onEnterFrame = this.frame;
Whenever you reference variables inside the frame function, remember to use this, eg: this._x.
-
Yes, those variaqbles always gave me trouble whenever I tried that, thanks for the help. Iam not pretty sure though if it will be much faster but it would be more organized for sure
-
Heli Attack!
The abundance of enterFrames will kill you.
Best thing to do is throw all the MC's into an array, and call a function in them explicitly.
-
Are you talking about checking through a for loop? I already done that and did'nt see much performance gain. If you're talking about something else than can you please show me a rough example?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|