Flash窗口ActionScript功能

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flash窗口ActionScript功能相关的知识,希望对你有一定的参考价值。

Taken from a lynda.com tutorial on learning actionscript. Lots of comments for the moment.
  1. //Create a global variable to hold the current top depth available
  2. var nTopDepth:Number;
  3. //Create an associative array to store the names of the opened windows
  4. var oOpenedWindows:Object = new Object();
  5.  
  6. //Add the 2 event handles to the buttons. Passes the id name through to the addWindow function.
  7. mcButtonOne.onRelease = function():Void {
  8. addWindow("WindowOne");
  9. };
  10. mcButtonTwo.onRelease = function():Void {
  11. addWindow("WindowTwo");
  12. };
  13.  
  14. function addWindow(sLinkage:String):Void {
  15. //If a value already exists in the associative array for the window, return.
  16. if(oOpenedWindows[sLinkage] != undefined) {
  17. oOpenedWindows[sLinkage].swapDepths(nTopDepth);//if the window exists, bring the existing window to the top depth
  18. return;
  19. }
  20. var nIndex:Number = this.getNextHighestDepth();//get the next highest level to put the window on
  21. var mcWindow:MovieClip = this.attachMovie(sLinkage, "mcWindow" + nIndex, nIndex);//attach the selected window and apply the next highest depth
  22. mcWindow._x = 100;//set selected window to 100px
  23. mcWindow._y = 100;//set selected window to 100px
  24. nTopDepth = nIndex;//set the nTopDepth to nIndex we aquired above.
  25. oOpenedWindows[sLinkage] = mcWindow;//Insert a value into the associative array
  26.  
  27. mcWindow.mcWindowBackground.onPress = function():Void {
  28. this._parent.swapDepths(nTopDepth);//swap the selected window with the current top depth to bring it to the front
  29. this._parent.startDrag();//target the window background, then its parent to add a drag function onPress
  30. };
  31. mcWindow.mcWindowBackground.onRelease = function():Void {
  32. this._parent.stopDrag();//target the window background, then its parent to remove a drag function onRelease
  33. };
  34. mcWindow.mcWindowBackground.onReleaseOutside = mcWindow.mcWindowBackground.onRelease;
  35.  
  36. mcWindow.mcCloseSquare.onRelease = function():Void {
  37. delete oOpenedWindows[sLinkage]//remove the window from the array on close
  38. this._parent.removeMovieClip();//remove the movie clip when you press the close button.
  39. };
  40. }

以上是关于Flash窗口ActionScript功能的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3:在 Flash embed 中失去焦点时保持 textarea UIscrollbar 位置

Flash actionscript 3 功能需要鼠标点击事件吗?

子数涵数·Flash——初识ActionScript

Actionscript 3 vs Haxe:为新的 Flash 项目选择哪个?

ActionScript 3 Flash Preloader as3代码就像苹果风格。

Actionscript 3 Flash 键盘事件