To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here


A Flash Developer Resource Site

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Reply
 
Thread Tools Search this Thread Display Modes
Old 11-02-2009, 10:08 PM   #1
jonis56
Junior Member
 
Join Date: Oct 2009
Posts: 10
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.
jonis56 is offline   Reply With Quote
Old 11-02-2009, 11:39 PM   #2
gparis
Super Moderator
 
Join Date: Aug 2000
Location: Montréal
Posts: 13,242
Since onLoadInit is an event of the MovieClipLoader Class, i gotta ask, in your example myfunction is your listener's name?

gparis
__________________


AS 2.0 Forum Guidelines || Use PHP tags for code samples || Flash9 LiveDocs || AS 2.0 Language reference (CS4)
gparis is offline   Reply With Quote
Old 11-03-2009, 12:25 AM   #3
jonis56
Junior Member
 
Join Date: Oct 2009
Posts: 10
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.
jonis56 is offline   Reply With Quote
Old 11-03-2009, 05:04 AM   #4
jonis56
Junior Member
 
Join Date: Oct 2009
Posts: 10
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?
jonis56 is offline   Reply With Quote
Old 11-03-2009, 02:47 PM   #5
gparis
Super Moderator
 
Join Date: Aug 2000
Location: Montréal
Posts: 13,242
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
__________________


AS 2.0 Forum Guidelines || Use PHP tags for code samples || Flash9 LiveDocs || AS 2.0 Language reference (CS4)
gparis is offline   Reply With Quote
Old 11-03-2009, 04:15 PM   #6
jonis56
Junior Member
 
Join Date: Oct 2009
Posts: 10
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
jonis56 is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Flash ActionScript

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:09 AM.


internet.commerce
Be a Commerce Partner
 »  »  »  »  »  »  »
 »  »  »  »  »  »
 

    

Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.