Link button in action script3 + fade out in jQuery integration

﹥>﹥吖頭↗ 提交于 2019-12-24 06:58:37

问题


I need help. I'm a graphic designer and i new to jQuery. In AS3 i find nice jQuery script - if you click to link the website its fade out and new site fade in.

I use custom.js in html5 page

$(document).ready(function() {
    $("body").css("display", "none");
    $("body").fadeIn(2000);
    $("a").click(function(event){
        event.preventDefault();
        linkLocation = this.href;
        $("body").delay(2000).fadeOut(2000, redirectPage);      
    });
    function redirectPage() {
        if (location.href.indexOf('reload')==-1) location.replace(location.href+'?reload');
window.location = linkLocation;
}
});

And I make 3 animated buttons in Flash and I use this code in Action Script 3 (this effect http://youtu.be/_p6vB6pG2lE) Ofcourse I don't use sound ;) Only animation.

  btn1.addEventListener(MouseEvent.CLICK, onClick);
    btn1.addEventListener(MouseEvent.ROLL_OVER, btnOver);
    btn1.addEventListener(MouseEvent.ROLL_OUT, btnOut);

    btn2.addEventListener(MouseEvent.CLICK, onClick2);
    btn2.addEventListener(MouseEvent.ROLL_OVER, btnOver);
    btn2.addEventListener(MouseEvent.ROLL_OUT, btnOut);

    btn3.addEventListener(MouseEvent.CLICK, onClick3);
    btn3.addEventListener(MouseEvent.ROLL_OVER, btnOver);
    btn3.addEventListener(MouseEvent.ROLL_OUT, btnOut);

    function btnOver(event:MouseEvent){
        event.target.gotoAndPlay("over");
    }

    function btnOut(event:MouseEvent){
        event.target.gotoAndPlay("out");
    }

    function onClick(event:MouseEvent):void {
    navigateToURL(new URLRequest("index.html"), "_self");
    }

    function onClick2(event:MouseEvent):void {
    navigateToURL(new URLRequest("portfolio.html"), "_self");
    }

    function onClick3(event:MouseEvent):void {
    navigateToURL(new URLRequest("contact.html"), "_self");
    }

And all it's working very nice but flash doesn't connect with jQuery script and site doesn't fadeout.

I testing integrate flash with jQuery via this method http://board.flashkit.com/board/showthread.php?768778-how-to-get-AS3-talking-to-jQuery

function myfadeout(){
// alert("myfadeout is called");
$('#box1').delay(3000).fadeOut(500);

}
Then in the last frame of my flash movie I called the function with actionscript2.0:

import flash.external.ExternalInterface;
stop();
ExternalInterface.call("myfadeout");

But my site fadeout automatic after 3 seconds and doesn't load contact.html for example because I don't click my button.

I only need a method to connect AS3 with jQuery - I click btn3 in flash and my site it's fadeout and load contact.


回答1:


I suggest to handle the navigation from your jQuery "myfadeout" function , it is better to have only one timing function than having two. You need to pass the page url to "myfadeout" function as a variable and handle it after your fade complete. your AS3 code should looks somthing like this :

import flash.external.ExternalInterface;

btn1.addEventListener(MouseEvent.CLICK, onClick);
btn1.addEventListener(MouseEvent.ROLL_OVER, btnOver);
btn1.addEventListener(MouseEvent.ROLL_OUT, btnOut);


btn2.addEventListener(MouseEvent.CLICK, onClick2);
btn2.addEventListener(MouseEvent.ROLL_OVER, btnOver);
btn2.addEventListener(MouseEvent.ROLL_OUT, btnOut);

btn3.addEventListener(MouseEvent.CLICK, onClick3);
btn3.addEventListener(MouseEvent.ROLL_OVER, btnOver);
btn3.addEventListener(MouseEvent.ROLL_OUT, btnOut);

function btnOver(event:MouseEvent){
    event.target.gotoAndPlay("over");
}

function btnOut(event:MouseEvent){
    event.target.gotoAndPlay("out");
}

function onClick(event:MouseEvent):void {
    ExternalInterface.call("myfadeout","index.html");
}

function onClick2(event:MouseEvent):void {
    ExternalInterface.call("myfadeout","portfolio.html");
}

function onClick3(event:MouseEvent):void {
    ExternalInterface.call("myfadeout","contact.html");
}

and your javascript should looks somthing like this:

<script type="text/javascript">
function myfadein(){
// alert("myfadein is called");
$('body').hide().fadeIn(3000);
}

function myfadeout(newURL){
  // alert("myfadeout is called : " + newURL);
  $("body").fadeOut(3000,function(){
    window.location.href = newURL;
  });
}
</script>


来源:https://stackoverflow.com/questions/19506501/link-button-in-action-script3-fade-out-in-jquery-integration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!