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 > Actionscript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 02-27-2008, 06:35 PM   #1
educasoft
Junior Member
 
Join Date: Mar 2003
Location: Belgium
Posts: 17
No more ROOT in Actionscript 3? Then how to do thie following???

Hi,

I can't find how to do the following.

On my main timeline I have 2 movieclips. mc1 and mc2

Now in mc1 there is nothing (empty at the moment) and in mc2 there is a button with a click event defined.

The clickevent should just do a mc1.graphics.lineTo(100,100);



But that seems to be a problem, since mc2 and mc1 are both added to the main stage, but they seem not to know anything about eachother.


I thought that it would be enough just to call root.mc1.graphics.lineTo(100,100) from the button in mc2, but that seems not to work.


Anyone know a good solution to be able to control movieclip1 from a button in movieclip2 if they are both movieclips on the main timeline?


Regards,

Bart
educasoft is offline   Reply With Quote
Old 02-27-2008, 09:58 PM   #2
Shokushu
Senior Member
 
Join Date: Jan 2008
Posts: 150
Lot's of things you can do. You can set up event listeners, you can put functions in the parent to deal with mc2's requests, or you can pass mc1 into mc2 as a variable.
And I think I'm forgetting one or more other ways you could do it...
Shokushu is offline   Reply With Quote
Old 02-28-2008, 03:16 AM   #3
derari
Junior Member
 
Join Date: Feb 2008
Posts: 24
What about "parent.mc1"?
Be happy that root is gone, now you can start to write proper code
derari is offline   Reply With Quote
Old 02-28-2008, 04:32 AM   #4
educasoft
Junior Member
 
Join Date: Mar 2003
Location: Belgium
Posts: 17
I'm absolutely not SAD. In fact I'm very happy with AS3 since its very powerfull and finally looks like a OOP language.

I discovered that you can still access the root by doing MovieClip(root).movieclip1


I do wonder however if this would also work for a externally loaded .swf




by the way. If I want to load a movie from an external .swf , then in most docs which I find they create a new movieclip, load the sxf content in it and add it as a child where it needs to be added.

Isn't there a way to load an external .swf into an allready existing movieclip on the stage ?
educasoft is offline   Reply With Quote
Old 02-28-2008, 05:16 AM   #5
fx.barrett
trace("AKA: Biro Barna");
 
Join Date: Oct 2007
Location: RO.Timişoara
Posts: 1,403
^ of course there is a way:

PHP Code:
var imageRequest:URLRequest = new URLRequest("random_quote.swf");
var
imageLoader:Loader = new Loader();

this.buttonName.addEventListener(MouseEvent.CLICK, functionName);

function
functionName(event:MouseEvent)
{
    
this.imageLoader.load(this.imageRequest);
    
this.addChild(this.imageLoader);
}
// end of functionName
__________________



| Windows MSN: birobarna [at] hotmail [dot] com | Skype: barna.biro |
WebLog: http://blog.wisebisoft.com/ |
| Software Developer / Flash & Flex Developer | Student ( Computer Science ) | Interested in: Sharing Knowledge |
|
Romanian Adobe Flash, Flex, AIR Forum: http://www.flashforum.ro/
| By perseverance the snail reached the ark. |

fx.barrett is offline   Reply With Quote
Old 02-28-2008, 06:30 AM   #6
educasoft
Junior Member
 
Join Date: Mar 2003
Location: Belgium
Posts: 17
Tnx,

1) Can I then replace the "this" keyword with the name of my allready existing movieclip ?

2) And does this remove the contents of that movieclip and replace it with the just loaded .swf content ? Or does it just ADD content to that movieclip but keep the content that was allready in the movieclip ?

3) If I don't need a dynamically created movieclip anymore, then how should I nicely clear it ? Just remove it as a child of its parent, or is it also better to destroy the object to free all its memory ? How to destroy it then ?


Kind regards,

Bart
educasoft is offline   Reply With Quote
Old 02-28-2008, 10:16 AM   #7
cancerinform
Mod
 
Join Date: Mar 2002
Location: press the picture...
Posts: 12,748
Quote:
Originally Posted by educasoft
I discovered that you can still access the root by doing MovieClip(root).movieclip1


I do wonder however if this would also work for a externally loaded .swf

by the way. If I want to load a movie from an external .swf , then in most docs which I find they create a new movieclip, load the sxf content in it and add it as a child where it needs to be added.

Isn't there a way to load an external .swf into an allready existing movieclip on the stage ?
It is better to use Object(root).whatever
If you are dealing with a movie extending Sprite or with both you will run into problems if you use either of them. If you know it is a Sprite or MovieClip only then use Sprite(root) or MovieClip(root).

You can load and external into MovieClip you want.
__________________

- The right of the People to create Flash movies shall not be infringed. -
| www.Flashscript.biz | Help a little girl, Ana, who has cancer. | Flashscript Biz Classes/Components | The new Event design pattern | Clothing for Haiti |

Last edited by cancerinform; 02-28-2008 at 10:19 AM.
cancerinform is offline   Reply With Quote
Old 06-08-2009, 12:30 PM   #8
1LostPuppy
Junior Member
 
Join Date: Jun 2009
Posts: 2
I have had the same problem, but with a bit of a twist.
I'm using MovieClip(root) in a private function of a class file bit even though I can trace that MovieClip(root) is the main time line it gives me an error about referencing a null object. the class file is directly attached to the movie clip on the stage, I have 3 frame an intro with a button to send the user to the second frame where the movie clip is and all the game elements are dynamically added to the MC then in the class file the private function among other things checks if teh game has ended and if so sends the user to the third frame which has the game over text and a button that they can click to play another game (get sent back to the second frame) but as soon as the variable that checks for the end of the game reaches zero the if condition is meet in there it just has a line MovieClip(root),gotoAndStop("gameover"); which is the third frame, if I comment out this line there is no error message but of cause no functionality either to go to the third frame. Does any one know what may be happening here as this should work by all accounts. Big mystery for me and I would like to understand what I have done wrong here.
1LostPuppy is offline   Reply With Quote
Old 06-09-2009, 08:41 AM   #9
cancerinform
Mod
 
Join Date: Mar 2002
Location: press the picture...
Posts: 12,748
This may be useful:

http://flashscript.biz/flashas3/path...rectorAS3.html
__________________

- The right of the People to create Flash movies shall not be infringed. -
| www.Flashscript.biz | Help a little girl, Ana, who has cancer. | Flashscript Biz Classes/Components | The new Event design pattern | Clothing for Haiti |
cancerinform is offline   Reply With Quote
Old 06-09-2009, 09:55 AM   #10
1LostPuppy
Junior Member
 
Join Date: Jun 2009
Posts: 2
Cheers for that, i found that the problem is being caused by my button, I'm still working on the button to see if I can find the problem.
1LostPuppy is offline   Reply With Quote
Reply

Go Back   Flash Kit Community Forums > Flash Help > Actionscript 3.0

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 03:40 AM.


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

    

Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers


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