简体   繁体   中英

Flash: ActionScript 3.0 MovieClip Widths

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 =[

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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