A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Can anyone tell me now this is done?

  1. #1
    whanabe flash junkie
    Join Date
    Oct 2001
    Location
    Santa Ana CA
    Posts
    95

    Can anyone tell me now this is done?

    when you mouse over the spider stuff comes out from the spider.
    http://www.thanea.com/deimos/html/index.html

    I've seen a couple sites that have the same feature but with diferent shapes.

    how is this acomplished?
    "Who are these Kids and why are they caling me dad!"

  2. #2
    Senior Member jbum's Avatar
    Join Date
    Feb 2004
    Location
    Los Angeles
    Posts
    2,920
    Here, I wrote you a little sample that does this kind of thing.

    The scripts are all in frame 1. It assumes the existence of a button named button_mc and a library movie with an export symbol called beastie_mc (the little critters).

    This is the code:

    Code:
    // The number of critters you want
    _root.maxBeasties = 100;
    
    // An invisible MC to hold them - sits underneath your button
    beastieFld = _root.createEmptyMovieClip("beastFld", 10);
    
    // This puts your button on top of all the critters
    // the only reason we need beastieFld is so we can accomplish that easily - otherwise i'd just use _root.
    beastieFld.swapDepths(button_mc);
    
    // Roll over script for your button
    button_mc.onRollOver = function()
    {
    	for (var i = 0; i < _root.maxBeasties; ++i)
    	{
    		var mc = beastieFld["bmc"+i];
    		if (mc == undefined)
    		{
    			mc = beastieFld.attachMovie("beastie_mc", "bmc"+i, i+1);
    			// 			mc._x = this._x;
    			mc._y = this._y;
    			mc.speed = 5 + random(5);
    			mc.onEnterFrame = function ()
    			{
    				var dx = (this.tx - this._x);
    				var dy = (this.ty - this._y);
    				this._x += dx/this.speed;
    				this._y += dy/this.speed;
    				if (dx < 5 && dy < 5) {
    					if (this.closing) {
    						this.removeMovieClip();
    					}
    					else {
    						this.tx = random(Stage.width);
    						this.ty = random(Stage.height);
    					}
    				}
    			}
    		}
    		mc.closing = false;
    		mc._xscale = mc._yscale = 30;
    		mc.tx = random(Stage.width);
    		mc.ty = random(Stage.height);
    	}
    }
    
    // Roll out script for your button
    button_mc.onRollOut = function()
    {
    	for (var i = 0; i < _root.maxBeasties; ++i) {
    		var mc = beastieFld["bmc"+i];
    		if (mc != undefined) {
    			mc.closing = true;
    			mc.tx = this._x;
    			mc.ty = this._y;
    			mc.speed = 5;
    		}
    	}
    }

    The hard part with this kind of thing (aside from being able to do it at all) is controlling the movement - constraining it to the area of interest, and making the motion look the way you want.

    For each critter, the variables this.tx and this.ty control where he's gonna go. I currently have them programmed to go all over the entire field.


    - jbum
    Attached Files Attached Files

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