A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] call one function from one mc to another

  1. #1
    Junior Member
    Join Date
    Oct 2009
    Posts
    13

    resolved [RESOLVED] call one function from one mc to another

    AS2

    In two movieclips how to call myfunction(parameter) so that the function loads only when it initializes like the onLoadInit method

    myfunction.onLoadInit = function(parameter) {

    trace("parameter==" + parameter);

    }

    I want to call a fucntion that does something like the above from the first mc while the function is declared in the second.

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    Since onLoadInit is an event of the MovieClipLoader Class, i gotta ask, in your example myfunction is your listener's name?

    gparis

  3. #3
    Junior Member
    Join Date
    Oct 2009
    Posts
    13
    Thank you really for the response!!

    As i searched yes it has to be a listener but i can not make it work. See below.

    This is what works now:
    In the first movieclip==mc1 i have the

    PHP Code:
    this._parent._parent.mc2.loadimage.loadClip(this._parent.image,this._parent._parent.mc2.image_mc); 
    and inside the mc2 i have

    PHP Code:
    var loadimage:MovieClipLoader = new MovieClipLoader();
    var 
    listener:Object = new Object();
    listener.onLoadInit = function() {
        
    image_mc.alphaTo(100,1,"",0);
        
    };
    loadimage.addListener(listener); 
    OK the above works very well and the image is loaded where i want it but i want to pass a parameter too that i can handle in mc2. Because of the nature of my rest code I want it to be done only in an onLoadInit. So i think that i have two options
    1)to make another listener that will read the parameter
    2)to use the same listener and read in there the parameter
    i don't know neither of both how to make them work...

    I tried to make a second listener like
    PHP Code:
    var myvar;
    var 
    listener2:Object = new Object();
    listener2.onLoadInit = function(myparameter) {
        
    trace("myparameter" myparameter);
    };
    myvar.addListener(listener2); 
    and call it from mc1 like previously
    PHP Code:
    this._parent._parent.mc2.myvar(myparameter); 
    Something is wrong with the
    var myvar; or the last "php" code.
    Any ideas?
    Last edited by jonis56; 11-03-2009 at 12:34 AM.

  4. #4
    Junior Member
    Join Date
    Oct 2009
    Posts
    13
    the problem is that i don't use the MovieClipLoader class in the second listener... so can i somehow have a function with a behavior like the onLoadInit that happens only one time?

    how else to pass a variable in mc2 from mc1?

  5. #5
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    how else to pass a variable in mc2 from mc1?

    mc1.somevar = mc2.someothervar;

    if the variable doesn't have a var prefix, ie: if its scope isn't restrained to the function's scope, there shouldn't be a problem. You could also in the 1st MCL's onLoadInit give the mc2 variable a value, or even set it there.

    That said, there cannot be an onLoadInit without a MCL, specially if you are not loading anything a second time around. So i suggest you follow the above solution.

    gparis

  6. #6
    Junior Member
    Join Date
    Oct 2009
    Posts
    13
    Quote Originally Posted by gparis View Post
    how else to pass a variable in mc2 from mc1?

    mc1.somevar = mc2.someothervar;

    if the variable doesn't have a var prefix, ie: if its scope isn't restrained to the function's scope, there shouldn't be a problem. You could also in the 1st MCL's onLoadInit give the mc2 variable a value, or even set it there.

    That said, there cannot be an onLoadInit without a MCL, specially if you are not loading anything a second time around. So i suggest you follow the above solution.

    gparis
    Oh my god... thank you my friend i didn't know this in bold. i have just tried it and it works

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center