dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: browser shaker

  1. #1
    Member
    Join Date
    Jan 2003
    Location
    Tallahassee
    Posts
    35

    browser shaker

    I placed a javascript in the html of a page containing a flash movie and in the movie I call the function, which shakes the browser window.

    I have a lot of processor on my machine and the affect happens quickly as desired, but on other machines with slower processors, the affect last a lot longer and hangs the movie on 1 frame for about 5 - 7 seconds and then moves forward.

    Question: Is there a better way of achieving this affect? I have seen it done within a Flash movie... but the only problem with that in my case is that my movie fills an entire browser window.

  2. #2
    FK's Super Loquacious Randomite ad_mtk2's Avatar
    Join Date
    Jun 2001
    Location
    Calgary, AB Born of bread in Bristol, UK
    Posts
    1,273
    what code are you using to shake the browser. There are some that have many attributes and will perform many different actions before shaking the browser. i find the following works well:

    Code:
    <SCRIPT LANGUAGE="JavaScript1.2">
    <!-- Hide this script from older browsers
    
    function shakeItUp() {
    	if (self.moveBy) {
    		for (i = 60; i > 0; i--) {
    			self.moveBy(0,i);
    			self.moveBy(i,0);
    			self.moveBy(0,-i);
    			self.moveBy(-i,0);
            	}
         	}
    }
    // -->
    </SCRIPT>
    if you get any trouble just ask.

  3. #3
    Member
    Join Date
    Jan 2003
    Location
    Tallahassee
    Posts
    35
    Mine is similar:

    <SCRIPT LANGUAGE="JavaScript1.2">
    <!-- Begin
    function init() { setTimeout("shake(20)",3000);
    }

    function shake(n) {
    if (self.moveBy) {
    for (i = 20; i > 0; i--) {
    for (j = n; j > 0; j--) {
    self.moveBy(0,i);
    self.moveBy(i,0);
    self.moveBy(0,-i);
    self.moveBy(-i,0);
    }
    }
    }
    }

  4. #4
    Member
    Join Date
    Jan 2003
    Location
    Tallahassee
    Posts
    35
    Someone just posted this reply to the same question over in the Macromedia forum:

    Copy this anywhere on frame 1 or 2 of your main timeline

    -----------------------------------------
    Movieclip.prototype.shakewin = function(amount){
    if (!amount) {amount=5;};
    var jsString;
    jsString = "javascript:function shakewin(n){";
    jsString += "if(parent.moveBy)";
    jsString += "{for(i = 10;i > 0;i--){";
    jsString += "for(j = n;j > 0;j--){";
    jsString += "parent.moveBy(0,i);";
    jsString += "parent.moveBy(i,0);";
    jsString += "parent.moveBy(0,-i);";
    jsString += "parent.moveBy(-i,0);";
    jsString += "}}}};";
    jsString += "shakewin(";
    jsString += amount;
    jsString += ");void(0)";
    getURL(jsString);
    }//End fucntion
    -----------------------------------------

    Then either from a frame just write

    shakeWin(); //strength default of 5

    or

    shakeWin(8); //8 iterations of shake

    From a button

    on(release){
    shakeWin(3);//3 iterations of shake
    }//End on

    --------------------------------------

    That's it.. no other code is required either in your html or in your Flash..
    This is achieved by writing a javascript string straight from Flash and invoking
    it on the browser.

    Note: This will only work in a browser. It will not shake a projector, or
    Flash!!

  5. #5
    FK's Super Loquacious Randomite ad_mtk2's Avatar
    Join Date
    Jun 2001
    Location
    Calgary, AB Born of bread in Bristol, UK
    Posts
    1,273
    thanks for posting.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center