【问题标题】:Link button in action script3 + fade out in jQuery integration动作脚本中的链接按钮3 + jQuery 集成中的淡出
【发布时间】:2013-10-21 23:21:48
【问题描述】:

我需要帮助。我是一名平面设计师,也是 jQuery 的新手。在 AS3 中,我找到了不错的 jQuery 脚本 - 如果您单击链接该网站,它的淡出和新站点淡入。

我在html5页面中使用custom.js

$(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;
}
});

我在 Flash 中制作了 3 个动画按钮,并在 Action Script 3 中使用此代码(此效果 http://youtu.be/_p6vB6pG2lE)当然我不使用声音;)只有动画。

  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");
    }

而且一切都很好,但是 flash 不能与 jQuery 脚本连接,并且网站不会淡出。

我测试通过这个方法将flash与jQuery集成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");

但我的网站在 3 秒后自动淡出,并且不加载contact.html,例如因为我没有点击我的按钮。

我只需要一种将 AS3 与 jQuery 连接的方法 - 我在 flash 中单击 btn3,然后我的站点将淡出并加载联系人。

【问题讨论】:

  • 需要使用ExternalInterface才能连接AS3和JS
  • 谢谢,但是这个js代码怎么用这个问题呢? "(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; } });"例如导入 flash.external.ExternalInterface; ExternalInterface.call("redirectPage");??非常感谢
  • ready 是一个 jQuery 事件。您必须将以$("body")...etc 开头的代码放在一个单独的函数(不是事件)中,并使用ExternalInterface 类从AS3 调用该函数。

标签: javascript jquery html actionscript-3 flash


【解决方案1】:

我建议从你的 jQuery “myfadeout” 函数中处理导航,最好只有一个计时函数而不是两个。 您需要将页面 url 作为变量传递给“myfadeout”函数,并在淡入淡出完成后处理它。 你的 AS3 代码应该是这样的:

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");
}

你的 javascript 应该看起来像这样:

<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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多