A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: [RESOLVED] Eventlistener problem.

  1. #1
    Juvenile Delinquent CVO Chris's Avatar
    Join Date
    Jul 2002
    Location
    Ulster, UK
    Posts
    520

    resolved [RESOLVED] Eventlistener problem.

    The following (shortened) is on the main timeline:
    PHP Code:
    buttonContainer.rotatingButtons.buttonName.addEventListener(MouseEvent.CLICKmoveButtonsForContent);

    function 
    moveButtonsForContent(evt:MouseEvent):void {
        if (
    containerCenter==true) {
            
    sections.closeContent.addEventListener(MouseEvent.CLICKcloseWindow);
            
    containerCenter=false;
            
    leftMargin=150;
            
    rightMargin=250;
            
    buttonContainer.play();
            
    nextSection=evt.target.name;
            
    sections.gotoAndPlay(nextSection);
        } else if (
    containerCenter == false) {
            
    sections.closeContent.alpha=0;
            
    nextSection=evt.target.name;
            
    sections.nextSection=nextSection;
            
    sections.play();
        }

    As the movieclip (rotatingButtons) plays, the buttons change layers due to them rotating in a psuedo-3D circle. The event listener only seems to work when the button is pressed before it is removed in one layer and added to another layer. I am therefore guessing the eventListener only works for the first instance of a button and once that button is removed the listener is no longer valid or working even if the button/instance is added again on the following frame.

    How can I make it so that when the movieclip plays, the event listener will work even if a button/instance has been removed from 1 frame and added on the next frame on a different layer. (if I'm not explaining this very well then let me know and I will post an example fla).
    Last edited by CVO Chris; 07-15-2010 at 06:43 PM.

  2. #2
    Senior Member
    Join Date
    Apr 2004
    Location
    LA
    Posts
    349
    If you are deleting a button, its event listener will never fire because it cannot be clicked.

    If you instantiate another instance of the same button (say from your library) then you would need to add the event listener when you instantiate the object.

    I'm not sure how you are adding/removing these buttons. Is it dynamically? Are you just adding buttons to your frames and layers in the flash IDE? If you have two button with the same instance name that are on different layers, these are separate buttons and each will need the event listener added.
    Write multiplayer games with FlashMOG 0.3.1
    Try the MyPlan Salary Calculator

  3. #3
    Juvenile Delinquent CVO Chris's Avatar
    Join Date
    Jul 2002
    Location
    Ulster, UK
    Posts
    520
    They are added in the Flash IDE. Here is the timeline within the movieclip:

    There are 8 buttons and they are rotating round (like a ferris wheel viewed head on) and they need to change depth as they go around and appear in front of each other or behind so I must delete the button and put it on a different layer (ie on the 16th frame all the buttons change layers but are always on the stage).

    There are no eventListeners in the movieclip as the eventlistener is in the main timeline as it has to access functions and variables that are stored there.
    Last edited by CVO Chris; 07-16-2010 at 12:07 PM.

  4. #4
    Juvenile Delinquent CVO Chris's Avatar
    Join Date
    Jul 2002
    Location
    Ulster, UK
    Posts
    520
    After much testing - Found it!

    To call a function on main timeline from 2 movieclips deep:
    PHP Code:
    MovieClip(parent.parent).functionName 
    So just had to put a modified version of my original eventlistener on each keyframe:
    PHP Code:
    aboutUs.addEventListener(MouseEvent.CLICKMovieClip(parent.parent).moveButtonsForContent); 

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