2014-01-16 2 views
1

을 사용하여 이미지를로드하면 최근 ActionScript 3을 배우기 시작했으며 이미 질문이 있습니다. 질문이 동일하게 유지됩니다. Loader.load (URLRequest) 객체를 사용하여 그림을 업로드하고 있습니다. 정상적으로 사진을로드하여 표시했습니다. 그러나 이미지 높이와 너비의 속성 값을 읽는 것은 불가능합니다. 대신 0을 발행합니다. 즉,이 작업을 수행한다 : URLRequest

var loader:Loader=new Loader(); 

var urlR:URLRequest=new URLRequest("Image.jpg"); 
public function main() 
{ 
loader.load(urlR); 
var h:Number = loader.height;// here instead of the width of the image of h is set to 0 
// And if you do like this:  
DrawText(loader.height.toString(10), 50, 50); // Function which draws the text as defined below 
// 256 is displayed, as necessary 
} 
    private function DrawText(text:String, x:int, y:int):void 
{ 
      var txt:TextField = new TextField(); 
txt.autoSize = TextFieldAutoSize.LEFT; 
txt.background = true; 
txt.border = true; 
txt.backgroundColor = 0xff000000; 

var tFor:TextFormat = new TextFormat(); 
tFor.font = "Charlemagne Std"; 
tFor.color = 0xff00ff00; 
tFor.size = 20; 

txt.x = x; 
txt.y = y; 
txt.text = text; 
txt.setTextFormat(tFor); 

addChild(txt); 
    }  

아마 값이 특수 기능을 통해 얻을 수 있어야 속성,하지만 책 K.Muka "괴로움을위한 액션 스크립트 3"에서 그렇게 할 필요가 있다고 말한다. 이 문제를 해결하도록 도와주세요. 미리 감사드립니다.

답변

2

그럼 간단합니다.
플래시는 인터넷에 집중되어 있으므로 이러한 문제가 발생합니다.

loader.load (urlR); 그것은로드 된 것을 의미하지는 않습니다. 따라서로드 사전에 이벤트가 끝나기 전에 Null
인 경우 특정 기능 대신 사용자의 접근 방식에 영향을 미칠 수있는 코드가 더 많습니다. 그래도 여전히 읽는 파일의 크기에 크게 의존합니다. 음, 일반적으로 모두 가사입니다. loader.contentLoaderInfo.addEventListener (Event.INIT, _onEvent), onEvent 및 read 속성에서 이벤트를 수신합니다.

2

이미지가로드 될 때까지 기다릴 필요가 있습니다. 에 eventListener을 첨부하십시오.

var urlR:URLRequest = new URLRequest("Image.jpg"); 
loader.load(urlR); 
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete); 

function loader_complete(e:Event): void { 
    // Here you can get the height and width values etc. 
    var target_mc:Loader = evt.currentTarget.loader as Loader; 
    // target_mc.height , target_mc.width 
} 

Loader

관련 문제