2012-07-23 2 views
0

'smokeobject'의 speed 속성을 enter_frame 리스너 'animatesmoke'에서 'movitesmoke'데이터 객체의 속성을 as3에있는 동일한 객체의 다른 속성을 참조하여 가져옵니다.

을 smokeobject 여기에 내 코드

매우 빠르게 매우 혼란 얻을 것입니다 당신이 할하려는
public function createRocketSmoke() 
    { 
     var smokeObject:Object = new Object(); 
     smokeObject.whiteSmoke = new Bitmap(new WhiteSmoke(0,0)); 
     smokeObject.whiteSmoke.x=targetX + Math.random()*4-8; 
     smokeObject.whiteSmoke.y=targetY + Math.random()*4-8; 

     smokeContainer=new MovieClip(); 
     smokeContainer.addChild(smokeObject.whiteSmoke); 
     addChild(smokeContainer); 

     var randomScale = Math.random(); 
     if(randomScale<.5) 
     randomScale = randomScale+.5; 
     smokeObject.whiteSmoke.scaleX= randomScale; 
     smokeObject.whiteSmoke.scaleY= randomScale; 
     smokeObject.speed = Math.random(); 
     smokeObject.whiteSmoke.rotation = Math.random()*360; 
     smokeObject.whiteSmoke.addEventListener(Event.ENTER_FRAME,animateSmoke);  

    } 
    public function animateSmoke(event:Event):void 
    { 
     //here i want the speed property of the 'smokeObject' 
    } 

답변

0

입니다.

나는 당신의 연기에 대한 클래스를 생성하고 그에게 update() 기능을 제공하는 것이 좋습니다 :

public class Smoke 
{ 

    // Properties. 
    private var _whiteSmoke:Bitmap; 
    private var _speed:Number = 0; 


    // Constructor. 
    public function Smoke(targetX:Number = 0, targetY:Number = 0) 
    { 
     // Prepare graphics. 
     _whiteSmoke = new Bitmap(new WhiteSmoke()); 
     _whiteSmoke.x = targetX + Math.random()*4-8; 
     _whiteSmoke. y = targetY + Math.random()*4-8; 
     _whiteSmoke.rotation = Math.random()*360; 
     _whiteSmoke.scaleX = whiteSmoke.scaleY = 0.5 Math.random() * 0.5; 

     // Apply random speed. 
     _speed = Math.random(); 
    } 


    // Update this smoke. 
    public function update():void 
    { 
     // 
     // Update this smoke here. 
     // 
    } 


    // The graphics for this smoke. 
    public function get whiteSmoke():Bitmap 
    { 
     return _whiteSmoke; 
    } 


    // The speed for this smoke. 
    public function get speed():Number 
    { 
     return _speed; 
    } 

} 

이보다 쉽게 ​​배열로 연기 개체를 업데이트 할 수 있도록하고 각을 업데이트하는 루프 :

// This array will hold all your Smoke objects. 
var allSmoke:Array = []; 

// Create some Smoke. 
var smoke1:Smoke = new Smoke(10, 10); 
var smoke2:Smoke = new Smoke(10, 10); 

// Add it to the array. 
allSmoke.push(smoke1); 
allSmoke.push(smoke2); 


// Prepare game loop. 
addEventListener(Event.ENTER_FRAME, update); 
function update(e:Event):void 
{ 
    // Loop through smoke objects and update them. 
    for each(var i:Smoke in allSmoke) 
    { 
     i.update(); 
    } 
} 
관련 문제