A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: AS3 - Make mc invisible

  1. #1
    Senior Member
    Join Date
    Nov 2001
    Posts
    111

    AS3 - Make mc invisible

    Hey,

    After a few years of using Flash I am creating my first project in AS3 and am running into some problems which are quite common involving targeting movieclips and controlling them.

    Basically I have a fla which has an MC on the timeline with an instance name of INFO_MC. Now i want this MC to be invisible when the swf starts and I have managed this by using the following code:

    Actionscript Code:
    INFO_MC.visible = false;

    This is fine. However I get stuck when I try to make INFO_MC visible when I click a button in a loaded swf.

    How would I target INFO_MC from a button inside a loaded swf. Do I need to add an event to the button and then have a listener on the root timeline which would turn INFO_MC visible when it hears that the button has been clicked?

    Any help would be greatly appreciated.

    Cheers,

    James

  2. #2
    Senior Member b18269's Avatar
    Join Date
    Jan 2006
    Location
    London, UK
    Posts
    167
    alpha = 0

  3. #3
    Senior Member
    Join Date
    Nov 2001
    Posts
    111
    Thanks and yeah I can turn the MC invisible using that code but the part I am stuck on is targeting INFO_MC from inside another movieclip and turning it visible again.

    In AS2 i would of written

    _root.INFO_MC._visible = true;

    and I know AS3 is different and I have read so many websites but just can't figure out how to do it from code inside a loaded swf....

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    Quote Originally Posted by jonnycasino View Post
    would of
    "would have"

    Although you could reach up the display list through a combination of parent and root properties, don't.

    Instead, have your button dispatch an Event which bubbles. Listen for that event in your main swf, and in the event listener function, turn your clip visible again.

  5. #5
    Senior Member b18269's Avatar
    Join Date
    Jan 2006
    Location
    London, UK
    Posts
    167
    oh right i miss read that, try this

    Actionscript Code:
    (MovieClip(root).INFO_MC.visible = false;

    not the best way, but works?

  6. #6
    Senior Member
    Join Date
    Nov 2001
    Posts
    111
    Thanks for the replies however I still haven't managed to get this working.

    As I will be turning INFO_MC visible and invisible a lot throughout my application I decided to create a function to do this.

    So to hide the mc when the movie starts i have the following code on the first frame which works just fine:

    Actionscript Code:
    function hideINFO():void {
    INFO_MC.visible = false;
    }

    hideINFO();

    And then my function to show the mc is as follows

    Actionscript Code:
    function showINFO():void {
    INFO_MC.visible = true;
    }

    Now my only problem is calling the showINFO function when I click a button in a loaded swf. The button is located in a swf loaded into an empty mc on the stage with the instance name of 'holder'. the button has the following code linked to it:

    Actionscript Code:
    INFO_BUT.addEventListener(MouseEvent.CLICK, InfoClick);
    function InfoClick(evt:MouseEvent) {
        trace('info clicked');
        showINFO();
    }

    I know I need some code in front of the showINFO(); function call as I need to target the main timeline where the function exists. I just can't figure out the path? DO i need to involve the 'loader' mc as the button sits within that?

    I am sure AS3 is better than AS2 but the migration is getting me really frustrated!

    Any help would really be appreciated. Thanks for taking the time to read this!

    James

  7. #7
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    *tap tap tap* Is this thing on?

    Read my earlier response.

    In main:
    Code:
    addEventListener("HIDE_INFO", hideInfo);
    addEventListener("SHOW_INFO", showInfo);
    function hideInfo(e:Event):void{
      INFO_MC.visible = false;
    }
    
    function showInfo(e:Event):void{
      INFO_MC.visible = true;
    }
    in the loaded swf:
    Code:
    INFO_BUT.addEventListener(MouseEvent.CLICK, InfoClick);
    function InfoClick(evt:MouseEvent) {
        trace('info clicked');
        dispatchEvent(new Event("SHOW_INFO", true));
    }
    //and similar for hide

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