Back to Entry Page

Anatomy of Emergent Duplication Projects ("dupeDemo" series)

duplication demo A duplication demo B
Demo A Demo B

Click the images above to view the demonstration projects.

Concept

These projects show how the duplicateMovieClip() function can be used to create open-ended or emergent designs in Flash. These projects are open-ended in the sense that they place no programmatic constraints on the number of movie clips they can contain: duplicateMovieClip() is used to add new instances of the basic clip (the ubiquitous dot) in response to rollovers.

Demo A: single replication

In this version, when the mouse passes within any instance of the dot movie clip, a new clip is generated. The original clip then jumps 30 pixels away. Here's the script:

onClipEvent(mouseMove){
  if(this.hitTest(_root._xmouse, _root._ymouse))
    {
      p++;
      duplicateMovieClip(this, p, p);
      xOrient = random(2);
      yOrient = random(2);
      if(xOrient == 0) 
        {
          xChange = 30
        }
      else
	    {
          xChange = -30
        }
      if(yOrient == 0) 
        {
          yChange = 30
        }
      else
        {
          yChange = -30
        }
      this._x = this._x+xChange
      this._y = this._y+yChange
    }
  }

The entire script is contained within an if condition that localizes mouse movement to the current clip--our familiar method for simulating a mouseOver event for movie clips.

The variable p holds an integer value that begins at zero and increases by one each time the script is executed. This integer is used both to name the duplicate movie clip and to specify the level to which it is assigned. This transaction happens in the duplicateMovieClip() statement.

Once a new clip has been created, the original must be moved out of the way so that both will be visible. The two variables xOrient and yOrient contol the slope of the line along which the original movie clip will move. Their values are randomly assigned, meaning that the displacement of the original movie clip can take any of four directions (right-up, right-down, left-up, left-down).

Since duplicate movie clips inherit the scripts of their parents, the user may roll over either the original movie clip or its new copy. Thus the process described here cascades, generating highly unpredictable, emergent patterns.

Demo B: multiple replication

In the second project, we take the main parts of the first and move them off into a function:

onClipEvent(mouseMove){
  if(this.hitTest(_root._xmouse, _root._ymouse))
    {
      howMuch = random(9) + 1
      for(i=0; i<howMuch; i++)
        {
          replicate()
        }			
    }
  function replicate()
    {
      p++;
      duplicateMovieClip(this, p, p);
      xOrient = random(2);
      yOrient = random(2);
      if(xOrient == 0) 
        {
          xChange = 30
        }
      else
        {
          xChange = -30
        }
      if(yOrient == 0) 
        {
          yChange = 30
        }
      else
        {
          yChange = -30
        }
      this._x = this._x+xChange
      this._y = this._y+yChange
    }
  }

As you can see, the if condition contains a loop that executes a random number of times between 1 and 9, each time running through the replicate() function. This makes the behavior of the movie clips even less predictable and dynamic.

Files

Source files for this demo are contained in the dupeDemo folder within multimediaShare on Crow. They are dupeDemo1a.fla and dupeDemo1b.fla.


University of Baltimore Logo

Copyright © 2002 School of Information Arts and Technologies