Loading...

Posts Tagged ‘ actionscript ’

  1. Flex and ActionScript Posters
    Check out the Flex, ActionScript and Adobe AIR posters.
  2. Adobe technology platform ActionScript reference for RIA development
    Download the guide:atp_ria_guide.pdf (PDF, 1.3 MB)

转载链接

The release of Flex Builder 2 is around the corner and though the next version of Flash is still a ways away, ActionScript 3 will be a big part of Flex 2 and the impending release of Flash Player 9 (which arrives with Flex). ActionScript 3 is the next step forward and to help with the transition (for those of you deciding to make it), I thought, since I’ve been working with AS3 a bit lately, I’d make a new Tip of the Day thread for ActionScript 3.0 to help people prepare. So here we go: Read more…

说干就干, 先来看看 Flash 内容大小自适应到窗口.
大家可能有wallop吧, 据我观察, wallop 中就是一个宽高均为 100% 的 Flash, 当改变窗口大小时利用 Stage.onResize 事件来改变 Flash 内容的大小及位置.
看了看 Flash 帮助, 虽然 Stage 对象中有 onResize 事件, 但不能直接用 Stage.onResize, 需要加一个侦听对象, 不爽 :( 不过 onResize 确实是个好东西, 作用不小 :D I like it~~~
看看我的代码吧:

PLAIN TEXT >> ACTIONSCRIPT:
  1. // 先建立一个名为 p_mask 的矩形 MC, 放置在场景中备用
  2. // 之后在场景第一帧写下这里的代码
  3. // 考虑到计算可能会经常使用这些数据
  4. // 所以先定义几个变量备用
  5. // 原始宽度
  6. var ow:Number = 550;
  7. // 原始高度
  8. var oh:Number = 400;
  9. // 改变后的宽度
  10. var nw:Number;
  11. // 改变后的高度
  12. var nh:Number;
  13. // 创建侦听对象
  14. var myListener:Object = new Object();
  15. // onResize 事件需要设置 Stage.scaleMode 为 noScale
  16. Stage.scaleMode = "noScale";
  17. // 绑定侦听器
  18. Stage.addListener(myListener);
  19. // 定义侦听函数
  20. myListener.onResize = function() {
  21.     nw = Stage.width;
  22.     nh = Stage.height;
  23.     setXY();
  24. };
  25. // 第一次运行
  26. myListener.onResize();
  27. // 定义改变尺寸函数
  28. function setXY() {
  29.     with (_root.p_mask) {
  30.         _x = (ow-nw)/2;
  31.         _y = (oh-nh)/2;
  32.         _width = nw;
  33.         _height = nh;
  34.     }
  35. }
  36. // 一切 OK, 发布预览
  37. // swf 和宽高都为 100% 的 HTML 均测试通过