3

次のコードでは、ボタン イメージのみがフレックス コードに埋め込まれています。しかし、html オブジェクトまたは埋め込みタグでは、高さと幅を指定する必要があるのはなぜですか。幅若干の誤差ありそう

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>
4

3 に答える 3

7

埋め込みタグの高さと幅は必須属性です。タグの定義と必須およびオプションの属性については、swfobjectまたはAdob ​​e を参照してください。

それらが必要な理由、またはそれらがないとページが壊れる理由を尋ねていますか (ヒント、最初の答えは 2 番目の質問です)

編集:

EMBED タグと OBJECT タグの幅と高さの属性を変更して、swf のサイズと正確に一致させる必要があります。

.mxml でアプリケーションの幅と高さを設定できます

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

scaleMode を「noScale」に設定すると、swf にスケーリングが表示されません。

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

Actionscript 3 を使用している場合 (そうあるべきです)、メイン クラスにメタデータを設定できます。

すなわち

[SWF(width="640", height="480")]
public class MyClass extends Sprite
{
    public function MyClass()
    {
        stage.scaleMode = StageScaleMode.NO_SCALE;
        stage.align = StageAlign.TOP_LEFT;
    }
}
于 2011-04-18T12:49:29.337 に答える
1

@Dominic Tancredi のコメントへの追加: OBJECT タグと EMBED タグの両方に WIDTH 属性と HEIGHT 属性が必要です。

于 2011-04-18T13:16:57.763 に答える
1

Applicationクリック可能な画像しか含まれていなくても、メインの mxml で幅と高さを指定する必要があります。
ページに と のフレックス イメージ (ボタン??) を含めるwidth: 400px場合height: 100pxApplicationタグは次のようにする必要があります。

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

objectそれにもかかわらず、HTML では、とタグの両方embedに同じwidthとを含める必要があり、タグの属性にもheight値を指定する必要があります。embedalignalign="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 が埋め込まれている場合は、script タグに次のものが含まれている必要があります。

<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>

html から mp3 のパスを指定したい場合は、この投稿を参照してください

更新 2

objectフレックス ボタンのサイズに基づいてhtml の幅と高さを設定するには、アプリケーションの 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、ボタンのサイズに合わせてサイズが変更されます。

これらの値 (幅と高さ) は JavaScript 関数に渡されますonFlashAppInited。これも更新する必要があります。

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";
}
于 2011-04-19T06:47:04.633 に答える