A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Targeting MC on main frame with a button from a MC within a MC !!HELP!!

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    1

    Targeting MC on main frame with a button from a MC within a MC !!HELP!!

    Hello all i am new to the coding world so please be patient with me
    So i have a looping animation of some thumbnails, the hierarchy goes like this
    Scene1(main timeline) -> imgBar(MC)->imgBarB(MC within the imgBar MC)
    My buttons symbols are in the last MC "imgBarB" where i have this code:

    Code:
    stop();
    ss1.addEventListener(MouseEvent.CLICK, mouseDownHandler1);
    function mouseDownHandler1(e:Event):void{
      dispatchEvent(new Event("Play1", true));
    }

    I want to control the Btns in my "imgBarB" MC to play a labeled frame(named "ssbox1") on another MC on the main timeline,this other MC goes like this:
    Scene1(main timeline)->ssbox_mc(MC where my labeled frame is)
    So on the maine timeline(Scene1) i have this code:

    Code:
    addEventListener("Play1", play1);
    function play1(e:Event):void{
      ssbox_mc.gotoAndStop("ssbox1");
    }
    Problem is , the code wont work, if someone could please tell me what i'm doing wrong or point me to another solution i'll really apreciate it

  2. #2
    Designer, Programmer, Musician angelhdz's Avatar
    Join Date
    Mar 2010
    Posts
    971
    Dynamic referencing.

    stop();
    imgBarB.ss1.addEventListener(MouseEvent.CLICK, mouseDownHandler1);
    function mouseDownHandler1(e:MouseEvent):void
    {
    this.parent["ssbox_mc"].gotoAndStop("ssbox1");
    }
    Instead of referencing to the movieclip directly, we reference its instance name, and as its name is a String, we won't have any
    display undefined errors. And to scope to the main timeline we use "this.parent", that means "this" (is the actual movieclip) "parent" (its parent, in this case the main timeline).

    And just an advise, why putting script inside movieclips? Is better to have all your script in the main timeline, unless you want to make a kind of component.

    Note: If that doesn't work for you, then your ss1 button is not inside the imgBarB movieclip as I thought, then replace this:

    ss1.addEventListener(MouseEvent.CLICK, mouseDownHandler1);
    Last edited by angelhdz; 03-25-2014 at 03:03 AM.
    Already mastering AS3. It was so fun. Now into Javascript and PHP and all its libraries

  3. #3
    . fruitbeard's Avatar
    Join Date
    Oct 2011
    Posts
    1,780
    Hi,

    Perhaps,
    PHP Code:
    addEventListener("Play1"play1);
    function 
    play1(e:Event):void
    {
        
    ssbox_mc.gotoAndStop("ssbox1");
    }

    function 
    mouseDownHandler1(e:Event):void
    {
        
    dispatchEvent(new Event("Play1"true));
    }

    with (imgBar)
    {
        
    imgBarB.ss1.addEventListener(MouseEvent.CLICKmouseDownHandler1);

    it may be easier for you to attach your *.fla file for us to inspect and see the layout properly.

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