2011-11-14 1 views

답변

4

다음과 같이 임의의 유효한 색상을 생성 할 수 있습니다 : Math.round(Math.random()*0xFFFFFF). 당신은 색상의 많은 제어가 필요한 경우 여기에 노동 계급이 범위, ​​또는

for(var i:int = 0; i < 5; i++) { 
    var num:uint = Math.round(Math.random()*0xFFFFFF); 
    trace(num.toString(16)); 
    var mc:Shape = addChild(new Shape()) as Shape; 
    mc.graphics.beginFill(num); 
    mc.graphics.drawRect(100*i,0,80,80); 
} 

: 나는 셰인 동의 QuasiUseful : AS3 Random Color Generator

+3

mc.graphics.endFill() ... – PatrickS

+1

이 경우 실제로 필요하지는 않지만 추가하는 것이 좋습니다. – shanethehat

1

예를 들어,이 5 개 무작위 색깔의 사각형을 그립니다. flash.geom.colorTransform을 사용하여 색상을 동적으로 변경하는 방법을 추가 할 수도 있습니다.

정확한 치수를 알지 않아도 불규칙한 것을 포함하여 모든 모양의 색상을 변경할 수 있습니다. Shane의 난수 생성기 코드와 결합 된 다음 메서드를 사용하여이 작업을 수행 할 수 있습니다.

import flash.geom.ColorTransform; 
const INVALID_HEX_COLOR_VALUE:uint = 16777216; //Value that exceeds color range (over #FFFFFF) 

function applyColorSchemeTo(obj:DisplayObject, otherColor:uint = INVALID_HEX_COLOR_VALUE):void { 
    if(obj != null){ 
     var colorTransform:ColorTransform = obj.transform.colorTransform; 
     if(otherColor < INVALID_HEX_COLOR_VALUE) 
     { 
      colorTransform.color = otherColor; 
      obj.transform.colorTransform = colorTransform; 
     }   
    } 
} 
관련 문제