A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: for loop - createEmptyMovie inside AS2 Class

  1. #1
    MR
    Join Date
    Jul 2000
    Location
    ATL
    Posts
    272

    for loop - createEmptyMovie inside AS2 Class

    This may be a stupid question but I want to see if this is a valid way of using classes, if so what would be the proper way to get this to work. If anyone could point me in the right direction that would be awesome.

    Charlie

    Code inside the Fall.as document
    Code:
    class Fall extends MovieClip {
    	//Constructor
    	function Fall(mc:MovieClip) {
    	}
    	function moveAround(yPos, xPos, speed) {
    		this.onEnterFrame = function() {
    			if ((Math.abs(_x-xPos)<1) && (Math.abs(_y-yPos)<1)) {
    				trace("done");
    				_x = xPos;
    				_y = yPos;
    				delete (this.onEnterFrame);
    			} else {
    				_x += (xPos-_x)*speed;
    				_y += (yPos-_y)*speed;
    			}
    		};
    	}
    	function buildMe(myClip, newName,myNumber) {
    		trace("RAN");
    		var myClip:MovieClip;
    		for (var i = 0; i<myNumber; i++) {
    			trace(i)
    			this.createEmptyMovieClip(myClip, newName+i, i);
    			trace(newName+i);
    			var myNewName:MovieClip = newName+i
    			myNewName._x = i*myNewName._width;
    			trace(myNewName._x);
    		}
    	}
    }
    code inside the swf
    Code:
    this.attachMovie("ball", "ball1", 1);
    _root.ball1.buildMe("ball1", "myBall",10);

  2. #2
    MR
    Join Date
    Jul 2000
    Location
    ATL
    Posts
    272
    If it is just a completly stupid question and I am not using this in the right way I would love to know

    Normally I would just set this up in a function and have it do its business etc.

    Charlie

  3. #3
    FK Slacker
    Join Date
    Jun 2000
    Location
    vancouver
    Posts
    3,208
    Not really sure what you're asking here...can you elaborate a bit?

    K.

  4. #4
    MR
    Join Date
    Jul 2000
    Location
    ATL
    Posts
    272
    I guess my whole goal here in my continual learning is to be able to have a lot of re-usable actionscript. So I decided to start with some code from an image viewer that I built. What it does is pulls in file names of photos from an array, loads them into movie clips and places them on the stage in a row etc. Using a for loop much like the one seen above. Here is a working version of it.

    http://www.foreverindecember.com/trigger/XML/

    So i was trying to figure out which code goes into classes and which I would just keep for internal operations. Or if I would be better off just keeping this inside of my movie.

  5. #5
    MR
    Join Date
    Jul 2000
    Location
    ATL
    Posts
    272
    so maybe it is just a stupid way to do it

  6. #6
    MR
    Join Date
    Jul 2000
    Location
    ATL
    Posts
    272
    OK I did it I got it.. it totally works - After many hours of 2nd guessing myself

    If it is the best way to do things.. I dunno
    Code:
    class Fall extends MovieClip {
    	//Constructor
    	function Fall(mc:MovieClip) {
    	}
    	var myNewName:MovieClip;
    	var myClip:MovieClip;
    	var newName:String;
    	var myNumber:Number;
    	function moveAround(yPos, xPos, speed) {
    		this.onEnterFrame = function() {
    			if ((Math.abs(_x-xPos)<1) && (Math.abs(_y-yPos)<1)) {
    				trace("done");
    				_x = xPos;
    				_y = yPos;
    				delete (this.onEnterFrame);
    			} else {
    				_x += (xPos-_x)*speed;
    				_y += (yPos-_y)*speed;
    			}
    		}
    	}
    	function buildMe(myClip, myNumber,newName) {
    		for (var i = 0; i<myNumber; i++) {
    			myClip.duplicateMovieClip(newName+i,i);
    			this.myNewName = _root[newName+i];
    			trace(this.myNewName._x);
    			trace(this.myNewName);
    			this.myNewName._x = i*this.myNewName._width
    			
    		}
    	}
    }
    this next part goes on the first frame of the movie
    Code:
    var myB:Fall = new Fall(squ);
    myB.buildMe(squ, 5, "balls");

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