2012-02-24 4 views
1

私はajaxを介して 'ページ'を介して進行するWebアプリケーションに取り組んでいます。各ページのコンテンツはxmlファイルにあり、app ajaxはxmlファイルであり、そこからページを作成してブラウザに吐き出します。フラッシュビデオと画像をどのようにプリロードするのですか?

これらのページの一部には、前のページにプリロードしようとしている動画や大きな画像があります。以下は、メディアがプリロードされているかどうかをチェックするために使用しているコードですが、ページに着陸すると、再びロードされているようです。

動画プレーヤーは、DOMに常に表示されます。使用されていない場合は、画面に表示されません。

私は新しいImage()を使用して、そのイメージにあまりにもイメージのキャッシュを与えると仮定しましたか?

var l_image = new Image(); 
//other stuff happens here 

switch(l_next.type) { 
    case 'st_animation': 
     if(l_next.video != undefined && l_next.video != '') { 
     l_videoSrc = String(l_next.video); 
     _videoPlayer.loadVideo(l_videoSrc); 
     delete l_next; 
     } 
     //give 2secs for the video to load atleast the first frame 
     setTimeout(p_callback, 2000); 
     break; 

    default: 
     if(l_next.image != undefined && l_next.image != '') { 
     l_imageSrc = 'files/'+ l_next.image; 
     delete l_next; 
     l_image.src = l_imageSrc; 
     //replace the image or append it 
     if(this.data.type == 'st_animation') { 
      _$image.html('<img src="'+ l_imageSrc +'" alt="" />'); 
     } 
     else { 
      _$image.prepend('<img src="'+ l_imageSrc +'" alt="" />'); 
     } 
     //trigger callback when loaded 
     if(l_image.complete) { 
      setTimeout(p_callback, 500); 
     } 
     else { 
      l_image.onload = function() { 
      setTimeout(p_callback, 500); 
      } 
     } 
     } 

とコールバック関数:事前に

/* 
* Goes to the page with the specified id 
*/ 
goTo : function(p_pageID) { 
    //empty content & show loader 
    _$content.empty(); 
    _currentPage = null; //empty the page data 
    //_$loader.fadeIn(500); 
    //get the page we're going to's data 
    var l_data = this.getData(p_pageID); 
    //instantiate this pages PageType sub-class 
    eval('_currentPage = new '+ l_data.type +'(l_data)'); 
    l_data = null; 
}, 


/** 
* Loads the xml of the page's id you pass it 
*/ 
getData : function(p_pageID) { 
    var l_cacheBuster = '?cacheBuster='+ _structure.course.settings.cache_buster, 
     l_xmlPath = './data/'+ p_pageID +'.xml'+ l_cacheBuster, 
     l_data = new Object(); 
    //ajax request 
    $.ajax({ 
    type: 'GET', 
    url: l_xmlPath, 
    dataType: 'xml', 
    async: false, 
    success: function(p_data) { 
     //convert the xml structure to json 
     l_data = $.xml2json(p_data); 
     //check for parsing error 
     if(l_data.text != undefined) { 
     var l_dataString = String(l_data); 
     if(l_dataString.indexOf('XML Parsing Error') > -1) { 
      trace(l_dataString); 
     } 
     } 
    }, 
    error: function(p_response, p_status, p_error) { 
     trace('Could not load "'+ l_xmlPath +"\"\r\n"+ p_status +': '+ p_error.name); 
    } 
    }); 
    return l_data; 
} 

おかげで...

答えて

関連する問題