Create a custom "top-level" function
by Ardy15jan » Tue, 18 Sep 2007 01:12:04 GMT
Hi, everybody !
I have some custom made functions that I tend to use quite often. I`ve put
them in a class and defined them as 'static', but I`m not such a big fan of
this procedure. I want to make a class that contains their definitions, import
it and then just use the functions as if they were defined in my current class.
Does anybody know how this could be achieved?
Thanks!
Re: Create a custom "top-level" function
by juankpro » Tue, 18 Sep 2007 01:32:09 GMT
One method is always inheriting from this class. This ways your new class has
access to this methods.
Another method is creating what is usually called a mix-in. You class must
have an static initialize(obj) method which receives any object or prototype
and adds methods to it. You will have to at least declare this mixed-in
properties though (onle declare them as properties, do not implement them).
Another solution, if you want the functions available everywhere is to create
_global methods.
The last solution I can think of is a class using the Singleton pattern, allow
the creation of only one global instance allowing access to this methods. To
create this singleton the normal procedure is to make constructor private, then
create an static get method which asks if an instance as already been created
and if not (first time) creates one. Like the Camera or Microphone classes do.
Re: Create a custom "top-level" function
by Ardy15jan » Tue, 18 Sep 2007 01:44:42 GMT
Thanks for all the options you gave me!
The one I`m really interested in is the mix-in one. Could you please give me some details and an example? Thanks again!
Re: Create a custom "top-level" function
by juankpro » Tue, 18 Sep 2007 02:00:00 GMT
The Class:
class MyClass{
public function method1(){
// Your method here
}
public function method2(){
// Your method here
}
private static instance:MyClass;
public static function initialize(obj):Boolean{
if(instance == undefined){
instance = new MyClass();
}
obj.method1 = instance.method1;
obj.method2 = instance.method2;
return true;
}
}
How to use it:
usage 1:
class ProjectClass{
public var method1:Function;
public var method2:Function;
public function ProjectClass(){
MyClass.initialize(this);
}
}
How to use it:
usage 2:
class ProjectClass{
private static var initialized:Boolean =
MyClass.initializeClass(ProjectClass.prototype);
public var method1:Function;
public var method2:Function;
}
Re: Create a custom "top-level" function
by Ardy15jan » Tue, 18 Sep 2007 02:19:31 GMT
Thaks, Juank! I`ll have a go with this mix-in class, and I`ll also try declaring the methods globaly, to see which one works best for me.
Thanks again! I really apreciate your help!
Similar Threads:
1.Accessing a function from a movieclip form a top level layer
Im having a dillema. my whole game rests on being able to access functions from
a movieclip inside a movieclip in a top level layer called "Cards" to another
layer called "Functions". I've used this code:
[i]play_modifier_card(this.num.text);[/i]
to access this function:
[i]function play_modifier_card(card_num){
trace(card_num);
}[/i]
It works OK when the function is in the movieclip but not when it is in a top
level layer. I tried "_root.play_modifier_card(this.num.text);" but it didn't
work. Any help appriciated. Thanks in advance.
2.button thumbnail rolling over to top level
3.Only top level Movie clip displays in browser
I've started created a movie in MX with movie clips on 2 levels. Level 50 is an
.swf containing a navigation bar with drop down menus, which is complete. Level
20 contains the .swf containing the main content, which I just started, but
wanted to check in a browser before I went to far. The movie displays fine in
the FlashPlayer, but when I bring it into GoLive and try to display it in IE or
just open it directly in IE, all that shows is the navigation bar (the .swf on
level 50).
In the .FLA, in the first scene (containing the navigation), first frame of
action level, I have the following actions:
stop();
loadMovieNum("apollo_main.swf", 50);
loadMovieNum("apollo_main_clip.swf", 20);
Any ideas?
Jim C.
4.Root level screen appears on top(?!)
I have been working with Screens/Slides/Forms for a while now, and LOVE it - no better way to pound out site navigation with minimum effort! Nice new feature.
I just had a very strange thing happen, where the root level "presentation" slide always appears on top of it's children slides. I have no idea why its default behavior has changed to do this, any help would be appreciated.
Also, has anyone else noticed a bug in Flash where it will lose track of a slide's properties and you have to manually go back and enter "mx.screens.Slide" or whatever to get it back to normal? This one stumped me for awhile until I stumbled on the missing slide property.
Thanks in advance,
/\/\ike
5.Can i use attachmovie to load a movie on the top most level
hi
i need to load a movieclip from the library on the top most level. im currently using the attachmovie function to load the movieclip from the library. this movie clip has an action on the timeline which loads an external movie (.swf). let me know how can this be achieved
6. Dynamic Scroll bar Level sits on top
7. using FlashVars in something other than top level movie
8. Menu Bar top-level only