Javascript ile Flash Boyutunu Değiştirme

11 Kasım 2009

Aşağıda sayfanızdaki flash dosyasının boyutlarını değiştiren javascript dosyası bulunmakta.  IE5.5, IE6, IE7, IE8, Firefox 3, Opera 10, Safari 4, Chrome 3 programlarında test edildi.

Kullanım

Düzgün çalışması için flash’ı sayfanıza yerleştirirken kullanıdığınız html <object> etiketine id vermeniz gerekiyor. Daha sonra fonksiyonları çağırırken kullanacağımız ‘id’ bu olacak. Örnek:

<object  id=”flashid” height=”500″ width=”650″
classid=”CLSID:D27CDB6E-AE6D-11cf-96B8-444553540000″
codebase=”http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0″>

</object>

  • Boyut değiştirme:
    flashResizer.resize(genislik, yukseklik,’flashid‘);
  • Büyütme:
    flashResizer.zoomin(’flashid‘);
  • Küçültme:
    flashResizer.zoomout(’flashid‘;

Kod

var flashResizer = {
    ZOOM_IN:1,ZOOM_OUT:-1,
    fo:null,ZOOM_FACTOR:0.1,
    findObj:function(_foid){if(_foid==undefined || _foid==null){return this.fo;} this.fo=null;if (window.document[_foid]) this.fo=window.document[_foid];else if (navigator.appName.indexOf("Microsoft Internet")==-1){if (document.embeds && document.embeds[_foid]) this.fo = document.embeds[_foid];}else this.fo = document.getElementById(_foid);return this.fo;},
    resize:function(_w,_h,_foid){if(this.findObj(_foid)){this.fo.width=_w;this.fo.height=_h;}return this;},
    zoom:function(_d,_f){if(this.findObj(_f)){var zf=1+_d*this.ZOOM_FACTOR;this.resize(this.fo.width*zf,this.fo.height*zf);}return this;},
    zoomin:function(_f){this.zoom(this.ZOOM_IN,_f);},
    zoomout:function(_f){this.zoom(this.ZOOM_OUT, _f);}
}

Açılamalı Versiyon

Not: Yukarıdaki kod ile bunun arasında açıklamalar dışında bir fark yok. İstediğiniz bir tanesini seçip kullanın.

var flashResize = {
    fo:null, //bulunan flash nesnesi
    ZOOM_FACTOR:0.1, // boyut değiştirme oranı çarpanı
 
    ZOOM_IN:1,
    ZOOM_OUT:-1,
 
    /**
     * flash nesnesini bulur
     * orjinali: http://blog.codefidelity.com/?p=14
     * @param _foid  flash id. id verilmezse en son kullanılan id geçerli olur
     * @return       flash nesnesi. bulunamazsa null döndürülür.
     */
    findObj:function(_foid){
        if(_foid==undefined || _foid==null){
           return this.fo;
        }
        this.fo=null;
        if (window.document[_foid]) this.fo=window.document[_foid];
        else if (navigator.appName.indexOf("Microsoft Internet")==-1){
            if (document.embeds &amp;&amp; document.embeds[_foid]) this.fo = document.embeds[_foid];
        }
        else this.fo = document.getElementById(_foid);
 
        return this.fo;
    },
 
    /**
     * resize flash to specified size
     * @param _w: yeni genişlik
     * @param _h: yeni yükseklik
     * @param _foid: flash id. id verilmezse en son kullanılan id geçerli olur
     * @return this
     */
    resize:function(_w, _h, _foid){
        if(this.findObj(_foid)){
            this.fo.width = _w;
            this.fo.height = _h;
        }
        return this;
    },
 
    /**
    * @param _d: Büyütme tipi. flashResize.ZOOM_IN veya 1 yakınlaştırma,
    *            flashResize.ZOOM_OUT veya -1 uzaklaştırma için.
    * @param _foid: flash id. id verilmezse en son kullanılan id geçerli olur
    * @return  this
    */
    zoom:function(_d, _foid){
        if(this.findObj(_foid)){
            var zf = 1 + _d * this.ZOOM_FACTOR;
            this.resize(this.fo.width*zf, this.fo.height*zf);
        }
        return this;
    },
 
    /**
     * @param _foid: flash id. id verilmezse en son kullanılan id geçerli olur
     */
    zoomin:function(_foid){
        this.zoom(this.ZOOM_IN, _foid);
    },
 
    /**
     * @param _foid: flash id. id verilmezse en son kullanılan id geçerli olur
     */
    zoomout:function(_foid){
        this.zoom(this.ZOOM_OUT, _foid);
    }
}

Bu yazıyı oylayın

1 Yıldız2 Yıldız3 Yıldız4 Yıldız5 Yıldız (2 oy, ortalama: 4,50 / 5)
Loading ... Loading ...

Konular: Programlama
Etiketler: , ,


Yorumlar

Yorum bırakın