A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Creating an Event Listener

  1. #1
    Junior Member
    Join Date
    Apr 2008
    Posts
    4

    Creating an Event Listener

    I'm trying to learn how to create an event listener with ActionScript 2 in Flash CS6. I took over some Flash projects at work and know only basic code, and have nobody to help with the more complex stuff! I've looked at quite a few tutorials and forum posts but can't figure out how to use the other code I've seen in my own project. I'll try to describe as best as I can.

    My main file has two movie clips called "content_mc" and "sideNav_mc" that I am loading and swapping swfs into. In the swf loaded into "content_mc" I have six buttons. When one of these buttons is clicked, it needs to load "menu.swf" into "sideNav_mc" and then gotoAndPlay the frame that correponds with the button that was clicked. So if a user clicks "button3_btn" then "menu.swf" will load and automatically start at frame 3.

    Can anyone help me figure out what code to use for this, using the swf/instance names I provided above? Thanks!

  2. #2
    Junior Member
    Join Date
    Apr 2008
    Posts
    4
    Here is the best I could come up with for the code but it's not working. It does load the movieclip into sideNav_mc but it doesn't go to the frame I need to. I suspect it has to do with the target paths in the loadListener function.

    var LoadListener:Object = new Object();

    loadListener.onLoadComplete = function(){
    _root.sideNav_mc.gotoAndPlay (3);
    }

    var mcLoader:MovieClipLoader = new MovieClipLoader();
    mcLoader.addListener(loadListener);

    button3_btn.onRelease = function(){
    mcLoader.loadClip ("missionSpace/menu.swf", _root.sideNav_mc);
    }

  3. #3
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Maybe you can adapt this...
    Code:
    var num = 0;
    var sideNavListener:Object = new Object();
    var sideNavLoader:MovieClipLoader = new MovieClipLoader();
    sideNavLoader.addListener(sideNavListener);
    sideNavListener.onLoadInit = goPage;
    
    var contentListener:Object = new Object();
    var contentLoader:MovieClipLoader = new MovieClipLoader();
    contentLoader.addListener(contentListener);
    contentListener.onLoadInit = prepBtns;
    contentLoader.loadClip("btns.swf",content_mc);
    
    function prepBtns(mc:MovieClip) {
            mc.button1_btn.onPress = loadMenu;
            mc.button2_btn.onPress = loadMenu;
            mc.button3_btn.onPress = loadMenu;
            mc.button4_btn.onPress = loadMenu;
            mc.button5_btn.onPress = loadMenu;
            mc.button6_btn.onPress = loadMenu;
    }
    function loadMenu() {
            num = this._name.charAt(6);
            sideNavLoader.loadClip("menu.swf",sideNav_mc);
    }
    function goPage(mc:MovieClip) {
            mc.gotoAndStop(num);
    }

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