Create a custom "top-level" function



  • 1. Accessing Variables from within a onLoad Function
    Hello, I cant seem to access parent variables from within a onLoad function for example. [i] this.s_method = "test val 1" this.a_array = "test val 2" // this.lv_serverSend = new LoadVars() // this.lv_serverRecieve = new LoadVars() this.lv_serverRecieve.onLoad = function(success) { trace(this.a_array) // returns undefined trace(_parent.a_array) // returns undefined trace(a_array) // returns undefined trace(_parent._parent.a_array) // returns undefined } [/i] I dont want to put the varaibles on the _root or global, as there could be multiple copies of this function running simultaniosly. I know im on the right track I just cant seem to work out the proper syntax. Thanks in advance !!!
  • 2. Need help with going to a scene
    I know this is basic stuff, but it is driving me nuts as I can't figure out why it doesn't work. :) I have a movieclip (which has some buttons in it) loaded onto the stage. I have assigned actionscript to a button in the movieclip, which when clicked on should take the user to the next scene. However, it doesn't work. If I place a button on the stage, it works, but as long as the button is nested inside a movieclip, going to the next scene doesn't work. I tried other methods instead, all of which also fail. One was to make another movieclip (with a frame action to go to the next scene in the timeline) and put that on the stage. I then made the button (in the original movieclip) to target the 'jump' movie to play, which in theory would take me to the next scene. It doesn't work either. This is very annoying as I am fast approaching my deadline for completing this work. I would appreciate any workarounds or solutions, maybe somebody has found the same problem? So, in a nutshell, I want to click on a button in a movieclip in one scene, which will take me to the next scene. Many thanks.
  • 3. XML cache
    im having trouble with the xml object. i call the getXML() function every 30 seconds to re-load the data. i know that the server is sending different xml pages every time, but the xml object doesn't change after the first load. this only happens in the browser, when i test the movie in flash, everything works fine. does xml have a cache, this would explain it. please help! xml_data = new XML(); xml_data.onLoad = XMLload; function getXML() { xml_data.load("some url"); } function XMLload(success) { //statements... }

Create a custom "top-level" function

Postby 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?

Re: Create a custom "top-level" function

Postby 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

Postby 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

Postby 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(){

 How to use it:
 usage 2:

 class ProjectClass{
 private static var initialized:Boolean = 

 public var method1:Function;
 public var method2:Function;

Re: Create a custom "top-level" function

Postby 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:


 to access this function:

 [i]function play_modifier_card(card_num){

 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:

  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,


5.Can i use attachmovie to load a movie on the top most level


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

Return to FLASH


Who is online

Users browsing this forum: No registered users and 34 guest