Actionscript 3.0 Изменение размера родителя без влияния на детей - PullRequest
0 голосов
/ 26 октября 2010

У меня есть родительский мувиклип с несколькими дочерними элементами.
Как изменить размер родительского объекта, не затрагивая дочерний мувиклип?

Напоминание: дети должны оставаться с родителем.

import flash.display.MovieClip;
import flash.events.MouseEvent;

/*The parents*/
var motherFather:MovieClip = new MovieClip();
motherFather.graphics.beginFill(0xAA0022);
motherFather.graphics.drawCircle(40, 40, 40);
motherFather.width=100
motherFather.height=100
motherFather.x=10
motherFather.y=60

addChild(motherFather);
  for (var i:Number=1; i<=6;i++){
   var children:MovieClip = new MovieClip();
   children.graphics.beginFill(0xFF0260);
   children.graphics.drawCircle(40, 40, 40);
   children.width=30
   children.height=30
   children.x=10 +(i*30)
   children.y=50
   motherFather.addChild(children);


  }
//CLICK ON STAGE TO RESIZE THE PARENT.
motherFather.addEventListener(MouseEvent.CLICK, ResizeParent);
function ResizeParent(e:MouseEvent){
 motherFather.width+=150;

}

Ответы [ 2 ]

1 голос
/ 26 октября 2010

Вот, пожалуйста:

import flash.display.MovieClip;
import flash.events.MouseEvent;

/*The parents*/
var motherFather:MovieClip = new MovieClip();
addChild(motherFather);

var fill:MovieClip = new MovieClip();
fill.graphics.beginFill(0xAA0022);
fill.graphics.drawCircle(40, 40, 40);
fill.width=100
fill.height=100
fill.x=10
fill.y=60

motherFather.addChild(fill);

  for (var i:Number=1; i<=6;i++){
   var children:MovieClip = new MovieClip();
   children.graphics.beginFill(0xFF0260);
   children.graphics.drawCircle(40, 40, 40);
   children.width=30
   children.height=30
   children.x=10 +(i*30)
   children.y=50
   motherFather.addChild(children);

   addChild(new MovieClip());
  }
//CLICK ON STAGE TO RESIZE THE PARENT.
motherFather.addEventListener(MouseEvent.CLICK, ResizeFill);
function ResizeFill(e:MouseEvent){
 fill.width+=150;
}

Что-то подобное может быть?

0 голосов
/ 26 октября 2010

Более или менее похоже на ответ Ричардса, за исключением прозрачности ...

Вы можете просто добавить прозрачный фон к вашему MovieClip motherFather и изменить его размер вместо изменения размера самого MovieClip motherFather.

var background:Shape = new Shape();
background.name = "background";

background.graphics.beginFill( 0 , 0 );
//add the rest of the graphics functions

motherFather.addChild(background );

function resize(event:MouseEvent):void
{
    motherFather.getChildByName("background").with += 150;
}

Кроме того, если вы собираетесь создавать фигуры, нет необходимости использовать MovieClips, использовать экземпляры Shape для дочерних элементов и Sprite для контейнера.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...