简体   繁体   English

Flash:ActionScript 3.0 MovieClip宽度

[英]Flash: ActionScript 3.0 MovieClip Widths

please help me, I'm completely lost in AS3.0 with MovieClip widths. 请帮助我,我完全不知道AS3.0具有MovieClip宽度。

Basically, I am coding a menu, which instead of having a scroll bar if there are too many items for the screen, uses a magnification effect, allowing the user to scroll along the menu using the mouse. 基本上,我正在编码一个菜单,如果屏幕上没有太多项目,则不使用滚动条,而是使用放大效果,从而允许用户使用鼠标在菜单上滚动。

My problem at the moment is with resizing the width (it's a horizontal menu) of the MovieClips (each icon on the menu is a MovieClip). 目前,我的问题是调整MovieClips的宽度(它是一个水平菜单)(菜单上的每个图标都是MovieClip)。

If the width is too small (not sure the lowest it can go), the movie clip doesn't show up. 如果宽度太小(不确定最小宽度),则影片剪辑不会显示。

But that's not the full problem, if i set a movie clip's width to 2.8 it still shows up, with the correct width. 但这不是完整的问题,如果我将影片剪辑的宽度设置为2.8,它仍然会以正确的宽度显示。

It's only after a for loop which resets the appropriate icons widths, and then my 'reposition()' method that the icons don't show up. 只有在for循环之后会重置适当的图标宽度,然后重新设置我的“ reposition()”方法,图标才会显示出来。

I'm clearly just not understanding some aspect of MovieClips or Numbers in AS3, hopefully someone can help. 我显然只是不了解AS3中的MovieClips或Numbers的某些方面,希望有人可以提供帮助。

'black' contains a list of movieclips (the menu icons). “黑色”包含电影剪辑列表(菜单图标)。

Here is the code where everything goes wrong (it goes wrong when 'iconWidth' is very small): 这是所有出错的代码(当“ iconWidth”非常小时出错):

//if there are icons to the left
if ((s-leftEffect) > 1){
  //loop over all icons to the left
  for (var lu:int = 0; lu <= s-leftEffect; lu++){
   //set the icon's new width
   black[lu].width = iconWidth;
  }
 }
 //if there are icons to the right
 if ((s+rightEffect) < numShowing){
  //loop over all icons to the right
  for (var ru:int = s+rightEffect; ru < numShowing; ru++){
   //set the icon's new width
   black[ru].width = iconWidth;
  }
 }
 reposition();
}

function reposition(){
 if (numShowing > 16){
  //set the first menu icon to the left of its container
  black[0].x = 0;
  //for all icons in the menu
  for (var i:int = 1; i<numShowing; i++){
   //set position according to width
   black[i].x = black[i-1].x + black[i-1].width;
  }
 }
}

so for example, if iconWidth is calculated to be 2.8, then the two for loops will resize all icons that should be resized to 2.8. 因此,例如,如果iconWidth计算为2.8,则两个for循环将调整所有应调整为2.8的图标的大小。

Then reposition places each icon next to each other. 然后重新放置每个图标的位置。

But the problem is that reposition doesnt work if the iconWidth is too small. 但是问题是,如果iconWidth太小,则无法重新定位。

BUT, in reposition, if i manually added a line to set an icon that currently has width 50 to width 2.8, it still shows up! 但是,在重新定位时,如果我手动添加一行以设置当前宽度为50到2.8的图标,它仍然显示! Please help =[ 请帮助= [

as mentioned in comments above, it's hard to tell anything specific using your code sample, but: 如上面的注释中所述,使用代码示例很难说出任何具体信息,但是:
* imho it's safe and convinient to calculate coordinates and sizes as int , not Number - half-pixel is never seen *恕我直言,将坐标和尺寸计算为int而不是Number是安全且方便的-永远不会看到半像素
* if i were you i'd changed scaleX and scaleY properties of the whole menu (or whatever is parent for your icons) if it doesn't fit, instead of messing with every child *如果我是你,我将更改整个菜单的scaleXscaleY属性(或图标的父级)(如果不合适),而不是与每个孩子搞混

also if you add more code (or maybe post an example on wonderfl.net) - let me know by commenting this answer please :) 另外,如果您添加更多代码(或可能在wonderfl.net上发布示例)-请通过评论此答案让我知道:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM