Abstract: According to the different parameters, intelligent display cellular layout, the effect of:
Production steps:
1. Build a MC binding name "MYMC" in the Library
2, build a document class, the code is as follows:
1 Package2 {3 ImportFlash.display.Sprite;4 5 /**6 * @author ChB7 * @data 2015-8-268 * @email [email protected]9 */Ten One Public classReseaulayoutextendsSprite A { - Private varContainer:sprite; - Public functionreseaulayout () the { - init (); - } - + Private functionInit ():void - { +container =NewSprite (); A This. AddChild (container); atcontainer.x = stage.stagewidth * 0.5; -CONTAINER.Y = 200; -SetLayout (15,175,3); - } - /* - * @param number of _count hexagons in * @param itemw hexagon Width - * @param gap interval to * @param type of honeycomb, a group of how many hexagons + * @param num number in each group - * the */ * $ Private functionSetLayout (_count: Number, ITEMW: Number, Gap: Number, type: Number= 3,num: Number= 1):voidPanax Notoginseng { - if(_count > 10) the { +Type = 5; A } the + varItemy: Number= ITEMW * Math.Cos (30*math.pi/180);//Represents the y-axis gap between every two hexagons - varItemX: Number= ITEMW * 0.5;//represents the X-axis gap between each of the two hexagons $ $ for(varI Number= 0; i<_count; i++) - { - varItem:sprite =NewMYMC ();//hexagon Unit, inside the library bound the container.addchild (item); - varGroupnum: Number= Int (i/Type);Wuyi if(num = = 1) the { -item.x = groupnum* (itemw+gap); WuITEM.Y = Itemy * 2; - } About Else if(num = = 2) $ { - -Item.x = ITEMW/2+groupnum* (ITEMW+GAP); -ITEM.Y = Itemy * 2-itemy-Gap; A + } the Else if(num = = 3) - { $Item.x = ITEMW/2+groupnum* (ITEMW+GAP); theITEM.Y = Itemy * 2 + itemy +Gap; the } the Else if(num = = 4) the { -Item.x = ITEMW/2+groupnum* (ITEMW+GAP) + ITEMW/2 +Gap; inITEM.Y = Itemy * 2-itemy * 2-gap*2; the } the Else if(num = = 5) About { theItem.x = ITEMW/2+groupnum* (itemw+3) + ITEMW/2 +Gap; theITEM.Y = Itemy * 2 + itemy * 2 + gap*2; the } +num++; - if(num = = (type+1)) the {Bayinum = 1; the } the } - } - the } the the}
Honeycomb arrangement Type