2010-02-11 12 views
0

안녕하세요 저는 여러분에게도 스케일이 외부 SWF를 배경 무비 클립에로드한다고 생각합니다. 일부 텍스트를 클립하고 재미있는 대각선과 약간의 화질을 만드는 예외적 인 경우에 효과적입니다. 나는 이것이 줄을 따라 어느 정도 크기를 결정할 때 약간의 차이가 있다는 느낌이 들었다. 무대 크기는 2560 x 1440 크기로 축소되었지만 높이와 너비가 와이드 스크린 형식에 맞지 않습니다. 내 머리를 들여 놓는 것을 도와주세요.AS3 스케일링 - 텍스트를 클립하고 사진의 대각선을 왜곡합니다.

제발, 나는 AS3에서 정말로 손이 아니다.

www.sirwin.co.uk

// 초기 크기 검사

checkStageSize()를 수행하는;

// 스테이지 크기가 변경 될 때 다시 확인하기 위해 등록하십시오. stage.addEventListener (Event.RESIZE, onResize, false, 0, true);

기능하여 onResize (예 : 이벤트) {

checkStageSize(); 

}

// 여기에 스케일링을 수행하십시오

기능 checkStageSize() : 무효 {

var wid:Number = stage.stageWidth; 

var hi:Number = stage.stageHeight; 

var needToScaleDown:Boolean = (wid < 0); // or some other test 

if (needToScaleDown) { 

    var scale:Number = wid/0; 

    backgroundRectangle.scaleX = backgroundRectangle.scaleY = scale; 

} else { 

    backgroundRectangle.scaleX = backgroundRectangle.scaleY = 1; 
} 

}

stop(); var portRequest : URLRequest = new URLRequest ("main.swf");

var portLoader : Loader = new Loader();

portLoader.load (portRequest); backgroundRectangle.addChild (portLoader);

+0

일부 이미지 또는 추가 정보를 제공 할 수 있습니까? 'wid/0'심각하게? - 실제 코드는 될 수 없습니다. – Daniel

답변

0

코드에는 몇 가지 문제가있는 것으로 보입니다. 하나는 기술적 인 것이고 다른 하나는 근본적인 것입니다.

정확히 어떤 코드 (이 경우에는 - http://www.sirwin.co.uk/two.swf)가 보이는지 확인하기 위해 파일을 디 컴파일해야했습니다.이 파일은 1.9MB이며, 일부 파일을 포함하는 플래시 파일의 경우 매우 큽니다 사진. 더 나은 방법은 이러한 이미지를 외부 폴더에 넣고 필요에 따라 동적으로로드하는 것입니다.많은 장점이에 대한 있습니다 업데이트

  • 쉽게 - XML을 사용하고자하지 않는 사람들을 위해, 당신도 기반 구조를 생성 할 수있는 (
  • XML 또는 PHP가 구동되는 플래시 파일을 재 컴파일 할 필요가 없습니다 당신이 좀 더 모험적인 코드/OOP 부서에서 얻을 때 디렉토리에서 PHP)에서 폴더 구조 떨어져
  • 당신은 심지어 지퍼 폴더에 로딩 hydrotiks 큐 로더 클래스를 볼 수 있었다 - http://blog.hydrotik.com/2008/10/29/queueloader-rev-31-major-update-usage/
  • 당신도 사용할 수 flickr flash api가 flickr 계정에서 세트를 요청하고 동적으로로드합니다 (이 접근법이 당신은 flickr를 콘텐츠 관리 시스템으로 사용합니다.)

나는 기술적 인 문제를 먼저 해결할 수 있습니다. 이미지가 너무 크다는 것을 무시하십시오 - 라이브러리를 통해 또는 일부 코드를 통해 스무딩이 켜져 있는지 확인해야합니다. 가장 쉽지만 노동 집약적 인 방법은 라이브러리의 이미지에서 clikc를 두 번 클릭하고 "부드럽게 허용"이 켜져 있는지 확인하는 것입니다. 비록이 이미지가 크다 할지라도 켜져있을지라도 약간의 지그재그가 될 가능성이 있습니다.

두 번째 접근법은 프레임 변경시 동영상 클립에서 비트 맵 데이터를 추출하고 해당 내용을 삭제 한 후 smoothing 속성이 true로 설정된 컨테이너로 다시 그려 넣는 스크립트를 작성하는 것입니다. 코드가이 작업을 수행하기 위해, 당신이 각 섹션에 대한 사진의 배열을 생성하기 위해 사용하는 방법에 대한 매우 다양 하듯이

-하지만 코드의 핵심은 여기에서 찾을 수 있습니다 :

http://www.kaourantin.net/2005/12/dynamically-loading-bitmaps-with.html

하지만 정말로,이 길로 가면 9 야드 전으로 갈 수 있습니다.

파운드에 대해 파운드에 희망이 도움이됩니다!

+0

나는 smoothing 옵션을 시도했는데 아무런 차이가 없었습니다. 비트 맵 데이터를 추출 할 것입니다. 갤러리를 다시 생각하게 될 것입니다.하지만 주요 지점은 큰 이미지를 가지고 있습니다. 사이트는 좋은 품질 (최대 27 인치)까지 설계되었습니다. 다시 한번 감사합니다. – Scott

+0

아, 그리고 코드 바이스 (바지입니다) – Scott

+0

하하, 우리는 모두 어딘가에서 시작했습니다. 비트 맵 데이터의 몇 가지 예를 통해 당신을 도울 수 있습니다. 귀하의 사이트가 최대 27 인치 모니터처럼 보이기를 원합니다. 너는 사진 작가라는거야. 이미지는 당신의 거래입니다. 그러나, 당신을 고용 할 것 같은 사람들 - 얼마나 많은 사람들이 27 인치 모니터를 가지고 있습니까? 요점은 저울의 반대편에있는 사람들을 상처 입히고 있다는 것입니다 (상단). 볼만한 한 가지는 좋은 품질 (24 인치 화면 아래)과 높은 해상도 (27 인치 화면의 행운의 행운을 빕니다)에 대한 2 개의 폴더가있는 것입니다. 24 인치 화면의 – Beans

0

감사합니다. 콩 갤러리에서 더 좋은 방법을 찾아 볼 것입니다. SWF에서 이미지를 원했던 주된 이유는 디자인을 마쳤고 문제를 해결할 때 잠글 수 있고 비밀번호를 보호 할 수있는 기회가 적어졌습니다. 이미지 도난.

그러나 텍스트 (주로 버튼)의 클리핑이 그 어느 때보다도 나를 귀찮게합니다. 파일을 패키징하는 .SWF를 사용

stage.addEventListener(Event.RESIZE, resizeListener); 
stage.scaleMode=StageScaleMode.SHOW_ALL; 
stage.align=StageAlign.TOP_LEFT; 

function resizeListener(e:Event):void { 
    trace("stageWidth: " + stage.stageWidth + " stageHeight: " + stage.stageHeight); 


    // do the scaling here 

    var wid:Number=100/this.stage.stageWidth; 
    var hi:Number=100/this.stage.stageHeight; 
    this.stage.scaleX=this.stage.scaleY; 
    this.stage.scaleX=this.stage.scaleY; 

    this.stage.x = (100 - this.stage.width) * 0; 
    this.stage.x = (100 - this.stage.height) * 0; 
} 
0

많은 이유는 적합하지 않습니다,하지만 난 보안 측면에 대해 생각하지 않았다 :

I로 변경하는 코드입니다.

데모 : http://www.digital.leskiwis.com/sirwin/

다운로드 : http://www.digital.leskiwis.com/sirwin/sirwin.zip - 비록 물론 그 그물에 자사의 보안을하지 않을 경우 ...

나는 당신을 위해 여기에서 찾을 수 있습니다 아침에 약간의 데모를 채찍질

나를 몇 가지 기능을 설명하자

  • 이 hydrotik의 queueLoader 클래스를 사용합니다.그것은 바람을로드하고 모니터링하게합니다.
  • 모든 자산은 컴파일 된 SWF에 있습니다. 대기열 로딩의 가장 큰 특징 중 하나는 SWF의 프레임을 비트 맵 데이터로 그려내는 것입니다. (부드럽게하는 데 좋습니다)
  • 이미지의 크기가 조절되도록 크기 조정 이벤트를 사용합니다.
  • 가 SWF는 (X 720 1024) 크기의 720입니다 그래서 당신은 큰 이미지 (24에 더 큰 - 27 인치 스크린) 작은 확장 방법에 대한 좋은 아이디어를 얻을

크기 조정 청취자 :

  stage.scaleMode = StageScaleMode.NO_SCALE;  // the standard top left align, add some no scaling and throw in the event listener 
      stage.align = StageAlign.TOP_LEFT; 
      stage.addEventListener(Event.RESIZE, resizePhoto, false, 0, true); 

을 크기 조정 함수 : (우리는 photoWidth 및 photoHeight 변수를 한 번 저장합니다. 에 기초 편안 영역의 일부를 유지하면서 - 당신이 일을 위해 우리는이 중 일부는 지금까지 가장 좋은 방법의 동안)

 function resizePhoto(e:Event){ 

      var targetWidth = stage.stageWidth - buffer - photo.x  
      // this gives us the target width we want the photo. we can figure out what percent the image would need to be to make this, and use that as a scale mutiplication.. 

      var targetHeight = stage.stageHeight - buffer - photo.y  
      // this gives us the target height we want the photo. we can figure out what percent the image would need to be to make this, and use that as a scale mutiplication..    

      //note: add in some smart sizing on this - this means the photo resize stops when it hits a height or width limit..        
      var wMult:Number = (targetWidth/photoWidth) 
      var hMult:Number = (targetHeight/photoHeight) 

      if(wMult < hMult){ 
       photo.width = photoWidth * wMult 
       photo.height = photoHeight * wMult 
      }else{ 
       photo.width = photoWidth * hMult 
       photo.height = photoHeight * hMult 
      } 
     } 

을 모든 프레임을 확인 해달라고 그래서 이미지가로드, 그것은 충분히 향상되었습니다 파일에서 본 코드. 명확한 소리가 들리면 소리 치십시오. 전체 코드는 다음과 같습니다. 여기에서 모든 것을 다운로드 할 수 있습니다 : http://www.digital.leskiwis.com/sirwin/sirwin.zip

Enjoy!

package{ 

    import flash.ui.*; 
    import flash.display.*; 
    import flash.events.*; 
    import flash.text.*; 
    import flash.geom.*; 
    import flash.net.*; 
    import flash.utils.*; 
    import flash.media.* 

    import fl.controls.Button; 

    import com.hydrotik.queueloader.QueueLoader; 
    import com.hydrotik.queueloader.QueueLoaderEvent; 
    import com.hydrotik.queueloader.QLManager; 


    public class Sirwin extends MovieClip { 

     var sec_PERSONAL:Array = ['Animals', 'Macro']; // all of the topic sections... Note, the swf files need to match these names!   
     var sec_LENGTH:uint = 0; // the length of the loaded array 
     var sec_CUR:uint = 0;  // the length of the loaded array 
     var bmp_ARRAY:Array = []; // the container for the loaded section 
     var buffer:uint = 10;  // buffer in pixels for button placement 

     var _oLoader:QueueLoader = new QueueLoader(); 
     var photo:Sprite = new Sprite();  // holder for the photo to load into 

     var nextBut:Button = new Button();  // attach the next button from the library 
     var prevBut:Button = new Button();  // attach the prev button from the library 

     var photoWidth:Number // we store these as variables to improve performance, check once - not each time 
     var photoHeight:Number // we store these as variables to improve performance, check once - not each time 


     public function Sirwin(){ 
      trace("initialising Document..."); 
      addEventListener(Event.ADDED_TO_STAGE, popStageVars); // once the movie has been added to the stage, we can set up some more vars 
     } 

     private function popStageVars(e:Event){ 
      trace("popping stage vars...") 
      removeEventListener(Event.ADDED_TO_STAGE, popStageVars); 

      stage.scaleMode = StageScaleMode.NO_SCALE;  // the standard top left align, add some no scaling and throw in the event listener 
      stage.align = StageAlign.TOP_LEFT; 
      stage.addEventListener(Event.RESIZE, resizePhoto, false, 0, true); 

      _oLoader.addEventListener(QueueLoaderEvent.ITEM_COMPLETE, onItemComplete,false, 0, true); 
      _oLoader.addEventListener(QueueLoaderEvent.ITEM_PROGRESS, onQueueProgress, false, 0, true); 
      _oLoader.addEventListener(QueueLoaderEvent.QUEUE_COMPLETE, onQueueComplete,false, 0, true);     

      photo.x = 180 
      photo.y = buffer 
      addChild(photo) 

      setSections(); 
      setNav(); 
      toggleNav();     
     } 


     function resizePhoto(e:Event){ 

      // set photo dimensions to match stage; 
      photo.width = stage.stageWidth - buffer; 
      photo.height = stage.stageHeight - buffer; 

      // choose the larger scale property and match the other to it; 
      (photo.scaleX < photo.scaleY) ? photo.scaleY = photo.scaleX : photo.scaleX = photo.scaleY; 




     } 


     public function setSections(){ // this function places the section buttons on the stage... not so neccesary if you make your own buttons 

      for(var i:uint = 0; i < sec_PERSONAL.length; i++){ 
       var but:Button = new Button(); // attach the button from the library 
       but.label = sec_PERSONAL[i]  // give the button a label from the array of names 
       but.x = buffer 
       but.y = buffer*5 + (i * (buffer + but.height));     
       but.addEventListener(MouseEvent.CLICK, loadSection, false, 0, true); // weak handler for better garbage collection 
       addChild(but) 
      } 
     } 

     public function setNav(){ // this function places the nav buttons on the stage... better practice would be having their own class and dispatching mouse events to be listened for. Baby steps.. 
      nextBut.label = "Next >" 
      nextBut.x = buffer 
      nextBut.y = 350 
      nextBut.addEventListener(MouseEvent.CLICK, navForward, false, 0, true); 
      addChild(nextBut)    

      prevBut.label = "Previous <" 
      prevBut.x = buffer 
      prevBut.y = 400 
      prevBut.addEventListener(MouseEvent.CLICK, navBack, false, 0, true); 
      addChild(prevBut) 
     } 


     public function loadSection(e:MouseEvent){ 
      bmp_ARRAY = []; // reset the array to nothing 
      var swf:String = convertFolderName(e.target.label, '_') + ".swf"; 
      _oLoader.addItem("assets/"+swf, null, {title:"SWF Images", drawFrames:true}); 
      _oLoader.execute();       
     }  

     public function loadPhoto(){ 
      while(photo.numChildren){ 
        photo.removeChildAt(0);  // get rid of any existing photo 
      } 

      var bmp:Bitmap = new Bitmap(bmp_ARRAY[sec_CUR]);  // this gets the bitmap data from the array that has been loaded from the zip file 
      bmp.smoothing = true; // this should solve your smoothing issues 
      photo.addChild(bmp); 

      photoWidth = photo.width; // update the photos height and width for easy ref    
      photoHeight = photo.height; 
      resizePhoto(null);  // pass through a null event to avoid any compiler errors 
     } 


     public function convertFolderName(s:String, replacement:String):String{ // this function returns an underscore instead of a space       
      var trimmedValue:String = s.replace(" ", replacement) 
      return trimmedValue; 
     } 


     public function updateCur(n:Number){       
      sec_CUR += n;  // add a +1, or -1 to the current pointer 
      displaying.text = "Displaying: " + (sec_CUR + 1) + "/" + sec_LENGTH;  // this updates the 'number of/how many' text. you need plus one to adjust for arrays starting at 0 
     } 

     public function navForward(e:MouseEvent){ 
      updateCur(1) 
      toggleNav(); 
      loadPhoto(); 
     } 

     public function navBack(e:MouseEvent){ 
      updateCur(-1) 
      toggleNav(); 
      loadPhoto() 
     } 


     public function toggleNav():void{ //this function decides if the next or back should be shown 
      trace(sec_CUR + " - " + sec_LENGTH) 
      nextBut.visible = (sec_CUR >= sec_LENGTH-1) ? false : true 
      prevBut.visible = (sec_CUR <= 0) ? false : true 

      if(sec_CUR < 0){ 
       sec_CUR = 0;  
      } 

      if(sec_CUR >= sec_LENGTH-1){ 
       sec_CUR = sec_LENGTH-1; 
      } 
     } 

     // ----------------------------------------------------- queue loading event handlers 


     public function onQueueProgress(event:QueueLoaderEvent):void { // cheap preloading... 
      trace("\t>>onQueueProgress: "+event.queuepercentage); 
      displaying.text = "Loading: " + event.queuepercentage + "%"; 
     } 

     public function onItemComplete(event:QueueLoaderEvent):void { 
      trace("\t>> "+event.type, "item title: "+event.title + " type: " + event.fileType); 
      if (event.title == "SWF Images") { 
       bmp_ARRAY = []; 
       for (var i:int = 0; i<event.bmArray.length; i++) { 
        var bm:BitmapData = event.bmArray[i]     
        bmp_ARRAY.push(bm) 
       } 
      } 
     } 

     public function onQueueComplete(event:QueueLoaderEvent):void { 
      trace("** "+event.type); 

      sec_LENGTH = bmp_ARRAY.length 
      sec_CUR = 0; 

      updateCur(0) 
      toggleNav(); 
      loadPhoto();            
     }    


    }  
} 
+0

건배를 위해서 내가 나중에 가겠습니다. – Scott

+0

다른 사람이 내 크기 조정 기능에 대한 업데이트로이 코드를 발견하면 코드를 3 줄로 줄일 수 있습니다 (http://labs.findsubstance.com/2008/07/07/as3-scaling-techniques/의 호의). 새 코드가 업데이트되었습니다. – Beans