Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

variables and functions from child movieclip

This is a discussion on variables and functions from child movieclip within the Actionscript 3.0 newbies forums, part of the Flash CS3 eng category; on my main time line i have 2 varaibles: "LastSelected" and "Flagged", which are used to ...


Go Back   Forum Flash CS3 Flash CS4 > English Forums > Flash CS3 eng > Actionscript 3.0 newbies

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 25-07-08, 04:34
Junior Member
 
Join Date: Jul 2008
Posts: 8
Rep Power: 0
coma is on a distinguished road
Question variables and functions from child movieclip

on my main time line i have 2 varaibles: "LastSelected" and "Flagged", which are used to control the navigation on the site im making. I also have a function called UnClick() which perfroms the rollout animation for the btn last selected and then jumps to the flaaged section. these are all on the main timeline.

now ive created a button symbol that is inside a movieclip called "HomeContent" and i need it to navigate the main timeline to another label "Services" and to do so i need to assign the 2 variables and call the UnClick() function from within the MovieClip.

this sounds like a simple thing to do but im kinda new to flash and AS3
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 25-07-08, 14:30
Junior Member
 
Join Date: Jul 2008
Posts: 4
Rep Power: 0
spectator is on a distinguished road
Re: variables and functions from child movieclip

can you provide us with some code. :)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #3 (permalink)  
Old 26-07-08, 10:50
Junior Member
 
Join Date: Jul 2008
Posts: 8
Rep Power: 0
coma is on a distinguished road
Re: variables and functions from child movieclip

okay well its a bit hard to show the actual code (cause its long and messy) so ive made this small and simple fla file (Attached) to better demonstrate my need.

on the main timeline, in the "AS Root" Layer:
Code:
var String1:String="Hello ";
var String2:String="World!";
 
function OutPut():void{
    trace (String1+String2);
}
 
OutPut();
in the Movieclip HomeContent in the "AS Home" Layer:
Code:
btnOutPut.addEventListener(MouseEvent.MOUSE_DOWN, LetSee);
function LetSee(evt:Event):void{
 String1="Welcome "; // A variable declared on the main timeline, AS Root layer frame1
 String2="Stranger"; // A variable declared on the main timeline, AS Root layer frame1
 OutPut(); // A function declared on the main timeline, AS Root layer frame1
}
/*---------------------Error Messages---------------------
1120: Access of undefined property String1.
1120: Access of undefined property String2.
1180: Call to a possibly undefined method OutPut.
--------------------------------------------------------------*/
Attached Files
File Type: fla Global.fla (64.0 KB, 9 views)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #4 (permalink)  
Old 26-07-08, 11:14
Junior Member
 
Join Date: Jul 2008
Posts: 4
Rep Power: 0
spectator is on a distinguished road
Re: variables and functions from child movieclip

Now I can't think of something else but you can just put your code on the main timeline :)
where is your stop just add
Code:
stop();

HomeContent.btnOutPut.addEventListener(MouseEvent.MOUSE_DOWN, LetSee);

function LetSee(event:MouseEvent):void{
String1="Welcome ";
String2="Stranger"; 
    OutPut(); 
    
}
:)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #5 (permalink)  
Old 27-07-08, 06:08
Junior Member
 
Join Date: Jul 2008
Posts: 8
Rep Power: 0
coma is on a distinguished road
Re: variables and functions from child movieclip

hmm... i guess.
that would work but it really sucks that i cant do it from inside the movieclip (im sure a similar situation will come up sooner or later). so there is no way to call global varaibles or functions? that cant be right AS3 is meant to be a propper programing language that is meant to meet the standards the C+ and other languages are set to. it would really suck if AS3 cant.

im thinking that i may be able to set variables and call functions if i create a class that will set variables and handle functions for me. any ideas?

Last edited by coma; 27-07-08 at 06:11..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Flash Multi Gallery
  #6 (permalink)  
Old 27-07-08, 12:27
Junior Member
 
Join Date: Jul 2008
Posts: 4
Rep Power: 0
spectator is on a distinguished road
Re: variables and functions from child movieclip

Yes If you create class that will be a solution, but what you say about the code inside something else, well there is a way, but I only can think of the _root which is not accessible in AS 3.0. You should create a class :)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #7 (permalink)  
Old 03-08-08, 12:20
Junior Member
 
Join Date: Aug 2008
Location: Bangalore
Posts: 2
Rep Power: 0
meshach is on a distinguished road
Thumbs up Re: variables and functions from child movieclip

Hi
I also had the same problem as you and i read your question and also sow the answers you got. I was not too happy with the answers so i sat and worked this one out myself.

The good news is that you can access the coding from the main time line from within the movieclip.
What I did was inside a mouse event function I wrote


“event.currentTarget.root.string = "this also works";


I had created the variable called string which is a String (var string:String) in the main time line. Then I called for this variable from within the movieclip timeline and use the event.currentTarget.root as a prefix for a mouse event responding function. And this worked. And also I using the same prefix and called for a function from the main time line and it worked too.
I hope this will solve you problem
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #8 (permalink)  
Old 03-08-08, 12:36
Junior Member
 
Join Date: Aug 2008
Location: Bangalore
Posts: 2
Rep Power: 0
meshach is on a distinguished road
Thumbs up Re: variables and functions from child movieclip

Here i took some time and reworked on your file and it is working :) have fun
Attached Files
File Type: fla Global.fla (50.5 KB, 70 views)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #9 (permalink)  
Old 04-08-08, 09:17
Junior Member
 
Join Date: Jul 2008
Posts: 8
Rep Power: 0
coma is on a distinguished road
Re: variables and functions from child movieclip

What a champ. I'm going to have a look at the code after work. Thanks for your help!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Actionscript 2 declaring variables Aaron24 Flash CS3 eng 9 24-08-08 21:43
External Swf functions won´t work! madmad Actionscript 3.0 newbies 0 28-05-08 08:53
Tutorial 4 - the functions Flep Actionscript for beginners - tutorials 1 21-05-08 10:31
Help unloading a child stevekeen Actionscript 3.0 newbies 5 10-03-08 23:59
Tutorial 1 the variables Flep Actionscript for beginners - tutorials 0 01-11-07 06:47


All times are GMT. The time now is 11:28.


Powered by vBulletin versione 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap


FlepStudio
by Filippo Lughi
P.IVA 03605860406