Flash:ActionScript 3.0 影片剪辑宽度

发布于 2024-10-05 02:14:30 字数 1459 浏览 3 评论 0原文

请帮助我,我完全迷失在 AS3.0 的 MovieClip 宽度中。

基本上,我正在编写一个菜单,如果屏幕上的项目太多,则该菜单不会使用滚动条,而是使用放大效果,允许用户使用鼠标沿着菜单滚动。

我目前的问题是调整 MovieClip 的宽度(它是一个水平菜单)(菜单上的每个图标都是一个 MovieClip)。

如果宽度太小(不确定可以达到的最低宽度),则影片剪辑不会显示。

但这不是全部问题,如果我将影片剪辑的宽度设置为 2.8,它仍然会以正确的宽度显示。

只有在 for 循环重置适当的图标宽度之后,然后使用我的“reposition()”方法,图标才不会显示。

我显然只是不理解 AS3 中的 MovieClips 或 Numbers 的某些方面,希望有人可以提供帮助。

“black”包含影片剪辑列表(菜单图标)。

这是一切都会出错的代码(当“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;
  }
 }
}

例如, 如果 iconWidth 计算为 2.8,则两个 for 循环将调整所有应调整为 2.8 的图标的大小。

然后重新定位将每个图标彼此相邻。

但问题是如果 iconWidth 太小,重新定位不起作用。

但是,在重新定位时,如果我手动添加一行来将当前宽度为 50 的图标设置为宽度 2.8,它仍然会显示!请帮忙=[

please help me, I'm completely lost in AS3.0 with MovieClip widths.

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

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.

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.

I'm clearly just not understanding some aspect of MovieClips or Numbers in AS3, hopefully someone can help.

'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):

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

Then reposition places each icon next to each other.

But the problem is that reposition doesnt work if the iconWidth is too small.

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! Please help =[

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与往事干杯 2024-10-12 02:14:30

正如上面的评论中提到的,很难使用您的代码示例说出任何具体信息,但是:
* 恕我直言,将坐标和大小计算为 int 是安全且方便的,而不是 Number - 从未见过半像素
* 如果我是你,如果不合适,我会更改整个菜单(或图标的父级)的 scaleXscaleY 属性,而不是弄乱对于每个孩子

如果您添加更多代码(或者可能在 Wonderfl.net 上发布示例)-请通过评论此答案让我知道:)

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

also if you add more code (or maybe post an example on wonderfl.net) - let me know by commenting this answer please :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文