编写Flash AS代码实现按钮触发全屏动画

资讯 驱动中国 somesun 511 次阅读 0 条评论
分享 Q

Flash播放器升级到Flash Player 9,0,28,0后可以使网页中的Flash通过一个简单的按钮实现全屏显示,这和一些视频网站中的效果基本相同,下面我们看看具体怎么实现,不需使用Javascript脚本。

需要我们在网页中插入Flash代码时,必须加上下面的代码:

<param name="allowFullScreen" value="true" />

 

首先看一下效果:


下面我们介绍Flash中的做法。

启动Flash,制作一个按钮元件,然后把按钮放到主场景中,为按钮添加代码:

on(press){
  toggleFullScreen();
}

 

函数toggleFullScreen()是主要来控制窗口,函数定义如下。

//Don't scale the movie when the stage size changes
Stage.scaleMode="noScale";
//Align the stage to the top left
Stage.align = "TL";
//Function to toggle between fullscreen and normal size
//the toggle fullscreen button calls this function when pressed
function toggleFullScreen(){
  //if normal size, go to fullscreen, else go to normal size
  if(Stage["displayState"]=="normal"){
    Stage["displayState"]="fullScreen";
  }else{
    Stage["displayState"]="normal";
  }
}
//Create a listener for each time the Stage is resized
var resizeListener:Object = new Object();
//Called each time the stage is resized
resizeListener.onResize = function () {
  //Move the button to the center of the screen
  toggleFullScreenButton._x=Stage.width/2;
  toggleFullScreenButton._y=Stage.height/2;
}
//Add the listener to Stage
Stage.addListener(resizeListener);

 
这样就定义好了!

 

当我们把上面制作的Flash插入到网页中时,具体代码如下:

<object data="你的swf文件地址"
type="application/x-shockwave-flash" width="400" height="200" >
<param name="movie" value="你的swf文件地址" />
<param name="allowFullScreen" value="true" />
</object>

 

这样就可以看到前面的全屏和收缩效果了

版权声明:本文由驱动中国整理发布,转载需注明出处与原文链接。如有疑问请联系 editor@qudong.com
本文价值 成为第一个评分的人
登录后为本文打分
网友评论0 条评论
正在回复 的评论取消
评论加载中…
🔐

登录后参与互动

评论、点赞均可赚积分
连续签到、邀请好友也有奖励 🎁

电脑端: 微信扫码登录 微信内: 一键登录

微信扫一扫

打开微信「扫一扫」,分享本文到朋友圈或好友