2011-04-18 7 views
3

다음 코드에서 버튼 이미지 만 flex 코드에 포함되었습니다. 그러나 html 객체 또는 embed 태그에서 높이와 너비를 지정해야하는 이유는 있습니다. 우리는 일반 버튼의 높이를 지정하고 일부 오류를HTML로 된 SWF 파일의 높이와 너비

html

<div align="center"> 
    <br /> 
    <div style="display:block;width:100px;height:100px;" id="audio" 
     class="testsound" align="center"/> 
    <p class="clickable"> 
     <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
     width="400" height="100" id="myMovieName"> 
      <param name="movie" value="/media/players/testsound.swf"/> 
      <param name="soundurl" value="/media/players/music.mp3"/> 
      <param name="quality" value="high"/> 
      <param name="bgcolor" value="#FFFFFF"/> 
      <embed width="100" height="100" href="/media/players/testsound.swf" 
       src="/media/players/testsound.swf" 
       flashvars="soundUrl=/media/players/music.mp3" 
       quality="high" bgcolor="#FFFFFF" 
       name="myMovieName" loop="false" align="" 
       type="application/x-shockwave-flash"> 
      </embed> 
     </object> 
    </p> 
</div> 

MXML

<?xml version="1.0"?> 
<!-- embed/EmbedSound.mxml --> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> 

    <mx:Script> 
     <![CDATA[ 

      import flash.media.*; 

      public var snd:Sound = new sndCls() as Sound; 
      public var sndChannel:SoundChannel; 

      public function playSound():void { 
       sndChannel=snd.play(); 
      } 

     ]]> 
    </mx:Script> 
    <mx:Image id="loader1" click="playSound();" 
     source="@Embed(source='/opt/cloodon/site/media/img/speaker.gif')" /> 
</mx:Application> 

답변

1

클릭 가능한 이미지가 포함되어 있어도 Application의 너비와 높이를 주 mxml에 지정해야합니다! 당신이 width: 400pxheight: 100px의 플렉스 이미지 (버튼을 ??)가 당신의 페이지를 원하는 경우
, 다음 Application 태그가 같이해야합니다 그럼에도 불구하고

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="400" height="100"> 

그리고, 당신의 HTML에서, 당신은 둘 다 있어야 당신의 objectembed 태그는 동일한 widthheight이어야하며 embed 태그의 align 속성에도 값을 지정해야합니다 (예 : align="middle"). 귀하의 object 태그

<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" 
    width="400" height="100" id="myMovieName" 
    codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab"> 
    <param name="movie" value="/media/players/testsound.swf"/> 
    <param name="soundurl" value="/media/players/music.mp3"/> 
    <param name="quality" value="high"/> 
    <param name="bgcolor" value="#FFFFFF"/> 
    <!-- the embed tag does not have href attribute --> 
    <embed width="400" height="100" 
     src="/media/players/testsound.swf" 
     flashvars="soundUrl=/media/players/music.mp3" 
     quality="high" bgcolor="#FFFFFF" 
     name="myMovieName" loop="false" align="middle" 
     type="application/x-shockwave-flash" 
     pluginspage="http://www.adobe.com/go/getflashplayer"> 
    </embed> 
</object> 

가 어디 sndClass 선언 다른 유사합니다

?당신이 MP3가 내장 된 것이있는 경우, 스크립트 태그를 포함해야합니다 : 당신이 HTML에서 당신의 mp3 파일의 경로를 지정하려는 경우, 당신은 this post for reference 볼 수

<mx:Script> 
    <![CDATA[ 
     import mx.core.SoundAsset; 

     [Embed('/media/players/music.mp3')] 
     private var _sound:Class; 
     public var snd:SoundAsset = new _sound() as SoundAsset; 

     public var sndChannel:SoundChannel; 

     public function playSound():void { 
      sndChannel=snd.play(); 
     } 

    ]]> 
</mx:Script> 

.

업데이트 2

다음과 같이 플렉스 버튼의 크기에 따라 HTML object의 폭과 높이, 당신은 응용 프로그램 MXML 코드를 업데이트해야 설정하려면 : 그 처음

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
    width="1" height="1" backgroundColor="#bee3f6" 
    horizontalScrollPolicy="off" verticalScrollPolicy="off" 
    creationComplete="onCreationComplete()" viewSourceURL="srcview/index.html"> 
    <mx:Script> 
     <![CDATA[ 
      import mx.events.FlexEvent; 

      //This method will change the button's label ==> width. 
      public function sayWhat():void { 
       var _date:Date = new Date(); 
       extButton.label = "It's " + (_date.getHours() + 1) + ":" + _date.getMinutes() + 
        ((_date.getMilliseconds() % 2) == 0 ? ". nice." : ". very tired."); 
      } 

      public function onCreationComplete():void { 
       // binds this.sayWhat to the external interface, so when from 
       // javascript is called the compiled swf object's sayWhat function, 
       // it will be transferred to this.sayWhat. 
       ExternalInterface.addCallback("sayWhat", sayWhat); 

       // set the flash application's size to be exact the button's size. 
       this.width = extButton.width; 
       this.height = extButton.height; 

       try 
       { 
        // The js function: onFlashAppInited(width, height); 
        // The next line tells the external interface (the parent application: 
        // browser window), that this application has finished loading, its 
        // ready to be used. 
        // We're passing the button's width and height as parameters 
        // In js there has to be a global method with this name. 
        ExternalInterface.call("onFlashAppInited", extButton.width, extButton.height); 
       } 
       catch (e:Error) 
       { 
        trace(e.message + "\n" + e.getStackTrace(), e.name); 
       } 
      }   

      protected function onButtonUpdateComplete(event:FlexEvent):void 
      { 
       // if the button's size has changed, we notify the javascript to set the 
       // correct size to the object tag too. 
       if ((this.width != extButton.width) || (this.height != extButton.height)) 
       { 
        // set the application size 
        this.width = extButton.width; 
        this.height = extButton.height; 
        // notify the js about the change 
        ExternalInterface.call("onFlashAppSizeChanged", this.width, this.height); 
       } 
      } 

     ]]>    
    </mx:Script> 
    <mx:Button id="extButton" label="Do something!" updateComplete="onButtonUpdateComplete(event)" /> 
</mx:Application> 

주 이 응용 프로그램은 1x1 픽셀입니다 (적은 경우, 초기화되지 않습니다!).
onCreationComplete 처리기에서 단추의 크기와 일치하도록 크기가 변경됩니다.

이 값 (폭과 높이) 당신은 또한 업데이트해야 자바 스크립트 기능 onFlashAppInited에 전달됩니다 정확히 할 SWF에 맞게 수행해야 어떤 제안 나던 게시물에서

function onFlashAppInited(width, height) { 
    alert("Flash app inited!"); 
    appInited = true; 

    onFlashAppSizeChanged(width,height); 

    // remove the temporary swf container: tmp 
    document.body.removeChild(document.getElementById("tmp")); 
} 

function onFlashAppSizeChanged(width, height) { 
    flashApp.width = width + "px"; 
    flashApp.height = height + "px"; 
} 
+0

나는 mxml 및 html.But에서 높이와 너비를 설정하는 것에 대해 동의합니다. 기본적으로 flex의 버튼 크기를 알지 못하므로 기본 버튼이 지정된 경우 높이를 알아야합니다 너비와 html로 설정하는 방법 ..? – Naveen

+0

: -? flex의 onCreationComplete 메소드에서 버튼의 크기 (너비/높이)를 가져 와서 javacript로 전달할 수 있습니다 (flashAppInited 메소드를 매개 변수로 사용). 이렇게하면 자바 스크립트 측에서 버튼의 너비에 대한 알림을 받고 swf 객체의 크기를 똑같은 크기로 조정할 수 있습니다. – rekaszeru

+0

K .. 내가 어떻게 검색 할 수있는 링크를 알려주시겠습니까? 내가 ur 사이트를 보았습니다. 그 기능은 이미 차가워졌습니다. – Naveen

7

높이있을 것 같습니다 폭하지 않는 경우 W embed 태그의 Width는 필수 속성입니다. 태그 정의의 swfobject 또는 Adoberequired and optional attributes뿐만 아니라 유행어가 있습니다.

왜 그런지 묻습니다.이 필요하며, 없으면 페이지가 깨집니다 (힌트, 첫 번째 대답은 두 번째 질문 임).

편집 :

당신은 SWF의 크기에 정확히 일치하는 EMBED 및 OBJECT 태그의 폭과 높이 속성을 수정해야합니다. 당신이 "noScale로는"당신은 당신의 SWF의 크기 조정을 볼 수 없습니다하는 조절 모드를 설정하면

당신은 .mxml

<mx:Application width="300" height="200"> 

에서 응용 프로그램의 폭과 높이를 설정할 수 있습니다.

Actionscript 3 (꼭해야 할 것)에 있다면 기본 수업에 메타 데이터를 설정할 수 있습니다. @Dominic 탠 크레디의 의견에

[SWF(width="640", height="480")] 
public class MyClass extends Sprite 
{ 
    public function MyClass() 
    { 
     stage.scaleMode = StageScaleMode.NO_SCALE; 
     stage.align = StageAlign.TOP_LEFT; 
    } 
} 
+0

하지만 지금은 그것 정확한 크기의 html 파일 – Naveen

+0

좋아요, 위의 편집에서 조언이 더 많습니다. 희망이 도움이됩니다. –

+0

+1 explaination .. 고마워요 – Naveen

1

추가 : OBJECT 및 EMBED 모두 태그 WIDTH를 필요로 HEIGHT 속성.

관련 문제