2010-10-25 6 views
0

J'ai le parent movieClip avec plusieurs enfants dedans.
Comment redimensionner le parent sans affecter les enfants movieClip?Actionscript 3.0 Redimensionnement du parent sans affecter les enfants

Remarque: Les enfants doivent rester avec le parent.

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; 

} 
+0

Effectuez le remplissage en tant qu'enfant de motherFather également. – Rihards

+0

Que voulez-vous dire? J'avais déjà le motherFather.addChild (enfants); – NanoHead

Répondre

1

vous allez ici:

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; 
} 

Quelque chose comme ça peut-être?

+0

les enfants sont invisibles maintenant – NanoHead

+0

as-tu copié le code jusqu'à la fin? vérifiez si vous avez "}" à la fin du code. Parce que cela fonctionne pour moi parfait! – Rihards

+0

étrange, ça marche maintenant. merci – NanoHead

0

plus ou moins similaire à la réponse de Richards, sauf pour la transparence ...

Vous pouvez simplement ajouter un fond transparent à votre motherFather MovieClip et redimensionner qu'au lieu de redimensionner la motherFather MovieClip lui-même.

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; 
} 

Aussi, si vous allez seulement pour créer des formes, il n'y a pas besoin d'utiliser MovieClips, utiliser des instances de forme pour les enfants et un Sprite pour le conteneur.

+0

Merci beaucoup pour vos suggestions. J'aime toujours coller avec le MovieClip car il offre plus d'options, la performance n'est pas si mauvaise. L'idée de transparence est bonne. Merci – NanoHead

Questions connexes