开发者

Dynamically assign .onRelease to movieclip, with dynamic url too AS2

Sure this will be a simple fix, and I'm just not seeing the wood for the trees. I have a movie with a movieclip called scroller_mov. Inside it are 15 movieclips named pic1 thru pic15.

My code is on one frame, on the same level as scroller_mov. Just want to dynamically assign a click action to the pic1 - pic15 movieclips! have tried hardcoded links and dynamic, but no joy! Everything else works fine. Thanks if you can help!

stop();

lv_obj = new LoadVars();

lv_obj.load("flash_carou_data2.php");

lv_obj.onLoad = function(success):Void{
product_mod.product_model = this.product_models;

var products_data:Array = product_mod.pr开发者_Python百科oduct_model.split(",");
scroller_mov.prodmod1 = products_data[0];

for (i=0;i<15;i++){
    products_data[i] = products_data[i].split("&");
    scroller_mov["prodmod" + (i+1)] = products_data[i][0];
    scroller_mov["prodprice" + (i+1)] = products_data[i][3];
    scroller_mov["pic" + (i+1)].loadMovie(products_data[i][2]);

    scroller_mov["pic" + (i+1)].onRelease = function  () {
        getURL("http://www.mysite.com");
        //getURL(products_data[i][1]);
    }
};

};


You can do it just the way you do it in your code - but you have to wait for the loadMovie() to finish. When you load a MovieClip, all its properties are erased upon successful completion.

Set an interval to check for your MovieClip's getBytesLoaded() and getBytesTotal() methods, then assign the onRelease function when the clip is fully loaded. Here's a quick example, you can just copy and use the same checkLoaded function:

_root.test = _root.createEmptyMovieClip ("test01", _root.getNextHighestDepth());
_root.test.loadMovie ( "test.swf");

_root.checkLoaded =  function (clip) { 

   var bytesLoaded = clip.getBytesLoaded();
   var bytesTotal = clip.getBytesTotal();
   if (bytesLoaded > 0 && bytesLoaded == bytesTotal) trace ("loaded");
   else return;
   clearInterval (_root.interv);

   clip.onRelease = function () {
        trace ("release");
        getURL("http://www.google.com"); 
    } 
}

_root.interv = setInterval( _root, "checkLoaded", 100, _root.test);

You can assign the interval to any variable, it doesn't need to belong to _root. Make sure the first parameter of setInterval is the object where the checkLoaded method is contained, and the last parameter is the MovieClip you are loading into.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜