Results 1 to 2 of 2

Thread: help with as3 buttons

  1. #1
    Join Date
    Nov 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help with as3 buttons

    I seem to have hit a block when it comes to the AS3 coding, iv managed to get all of my code working but when it comes to adding buttons to connect to a url in the same page i cannot get the code to work. Can any one help me as im alot stumped.

    var ful_scr:Boolean = false;
    full_screen_mc.mouseChildren = prev_mc.mouseChildren = next_mc.mouseChildren = false;
    full_screen_mc.buttonMode = prev_mc.buttonMode = next_mc.buttonMode = true;
    full_screen_mc.addEventListener(MouseEvent.MOUSE_DOWN,onMD);
    prev_mc.addEventListener(MouseEvent.MOUSE_DOWN,navigate);
    next_mc.addEventListener(MouseEvent.MOUSE_DOWN,navigate);
    full_screen_mc.addEventListener(MouseEvent.MOUSE_OVER,onMOver);



    prev_mc.addEventListener(MouseEvent.MOUSE_OVER,onMOver);
    next_mc.addEventListener(MouseEvent.MOUSE_OVER,onMOver);
    full_screen_mc.addEventListener(MouseEvent.MOUSE_OUT,onMOut);
    prev_mc.addEventListener(MouseEvent.MOUSE_OUT,onMOut);
    next_mc.addEventListener(MouseEvent.MOUSE_OUT,onMOut);




    ---- its this section here which wont work

    animation_mc.buttonMode = true;
    animation_mc.addEventListener(MouseEvent.CLICK, onClick);
    animation_mc.addEventListener(MouseEvent.MOUSE_OVER, over);
    animation_mc.addEventListener(MouseEvent.MOUSE_OUT, out);

    function over(e:Event) {
    animation_mc.gotoAndPlay("in");
    }

    function out(e:Event) {
    animation_mc.gotoAndPlay("out");
    }

    function onClick(event: MouseEvent) {
    var home:URLRequest = new URLRequest("http://www.facebook.com");
    navigateToURL(home);
    }























    stage.addEventListener(Event.FULLSCREEN,checkIfIsFullscreen);

    function checkIfIsFullscreen(e:Event):void {
    if (stage.displayState == StageDisplayState.FULL_SCREEN) {
    full_screen_mc.text_txt.text = "| RETURN |";
    ful_scr = true;
    } else {
    full_screen_mc.text_txt.text = "| MAXIMISE |";
    ful_scr = false;
    }
    }

    function onMOver(e:MouseEvent):void {
    e.currentTarget.gotoAndPlay("s1");
    }
    function onMOut(e:MouseEvent):void {
    e.currentTarget.gotoAndPlay("s2");
    }
    function onMD(e:MouseEvent):void {
    if (ful_scr == false) {
    stage.displayState = StageDisplayState.FULL_SCREEN;
    full_screen_mc.text_txt.text = "- normal screen -";
    ful_scr = true;
    } else {
    stage.displayState = StageDisplayState.NORMAL;
    full_screen_mc.text_txt.text = "+ full screen +";
    ful_scr = false;
    }
    }
    function navigate(e:MouseEvent):void {
    if (e.currentTarget == prev_mc) {
    if (stage.getChildAt(0).cur_index >0) {
    stage.getChildAt(0).cur_index --;
    stage.getChildAt(0).loadBigImages(stage.getChildAt(0).cur_index);
    }
    } else {
    if (stage.getChildAt(0).cur_index < stage.getChildAt(0)._image_ar.length - 1) {
    stage.getChildAt(0).cur_index ++;
    stage.getChildAt(0).loadBigImages(stage.getChildAt(0).cur_index);
    }
    }
    updateText();
    }

    function updateText():void {
    if (stage.getChildAt(0).cur_index3 < 9) {
    if ( stage.getChildAt(0)._xml_length > 9) {
    info_mc.text_txt.text = "0" + (stage.getChildAt(0).cur_index3 + 1) + " / " + stage.getChildAt(0)._xml_length ;
    } else {
    info_mc.text_txt.text = "0" + (stage.getChildAt(0).cur_index3 + 1) + " / 0" + stage.getChildAt(0)._xml_length ;
    }
    } else {
    info_mc.text_txt.text = (stage.getChildAt(0).cur_index3 + 1) + " / " + stage.getChildAt(0)._xml_length;
    }
    }

    Pls help thank you

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Hi clocopps,

    Welcome to DD. Most of the code you posted has very little to do with the behavior you're describing. Below is how you should be coding it. Have a look at that and see if you can adapt it to your code.

    In the future, please use the [code] tags to paste code into your post. It makes it exponentially more readable.

    Code:
    button.addEventListener(MouseEvent.CLICK, goToAnchor);
    function goToAnchor(e:MouseEvent):void {
    	var url:String = "#top";
    	var request:URLRequest = new URLRequest(url);
    	try {            
    		navigateToURL(request);
    	}
    	catch (e:Error) {
    		// handle error here
    	}
    }

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •