dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [F8] Why is it that when I trace(this._x);...

  1. #1
    Board Idiot num97's Avatar
    Join Date
    Jun 2004
    Location
    South of Heaven
    Posts
    194

    [F8] Why is it that when I trace(this._x);...

    ...I get "NaN"?
    I don't have a bad sex life and I have the pictures to prove it.

  2. #2
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    In other words, you question is:
    Why is it that when I trace(this._x), i get Not A Number?

    There could be a lot of reasons depending on your other codes and set up.

    gparis

  3. #3
    Board Idiot num97's Avatar
    Join Date
    Jun 2004
    Location
    South of Heaven
    Posts
    194
    If a clip is on the stage, shouldn't it always have an _x and _y?
    I don't have a bad sex life and I have the pictures to prove it.

  4. #4
    Senior Member
    Join Date
    Aug 2000
    Location
    Montréal
    Posts
    14,141
    and that code is, i guess, on a frame inside that clip? then you should get a number.

    gparis

  5. #5
    Board Idiot num97's Avatar
    Join Date
    Jun 2004
    Location
    South of Heaven
    Posts
    194
    The trace resides within a function that is in a frame within the movie clip. I call the function using setInterval() like you suggested I do in another thread. The function is being called at the appropriate time, but anything that relies on the specific clip's properties (_x, _y, _xscale, etc.) come up as NaN.

    Is it the way I am referencing the clip?
    I don't have a bad sex life and I have the pictures to prove it.

  6. #6
    Board Idiot num97's Avatar
    Join Date
    Jun 2004
    Location
    South of Heaven
    Posts
    194
    On the first and only frame of the main timeline I have:

    Code:
    _global.i = 0;
    On the first and only frame of the movieclip, I have:

    Code:
    function Reproduction(){
    	max = 10;
    	min = 1;
    	maxa = 360;
    	mina = 0;
    
    	hypot = Math.floor(Math.random()*(max-min+1)+min); 
    
    	angul = Math.floor(Math.random()*(maxa-mina+1)+mina);
    
    	oppo = Math.sin(angul*Math.PI/180)*hypot
    	adja = Math.cos(angul*Math.PI/180)*hypot
    
    	if (angul <= 90){
    		_root.attachMovie("base_1","treetree" + _global.i + 1, _global.i + 1,{_x:adja + this._x, _y:oppo + this._y});
    	} else if ((angul >90) && (angul<=180)){
    		_root.attachMovie("base_1","treetree" + _global.i + 1, _global.i + 1,{_x:adja + this._x, _y:oppo - this._y});		
    	} else if ((angul >180) && (angul<=270)){
    		_root.attachMovie("base_1","treetree" + _global.i + 1, _global.i + 1,{_x:adja - this._x, _y:oppo - this._y});
    	} else if ((angul >270) && (angul<=360)){
    		_root.attachMovie("base_1","treetree" + _global.i + 1, _global.i + 1,{_x:adja - this._x, _y:oppo + this._y});
    	}
    	_global.i = _global.i + 1;
    	trace("hypot is " + hypot);
    	trace(this._y);
    }
    
    function Death(){
    	maxa = 2;
    	mina = 0;
    	Yup = Math.random() * (maxa - mina + 1) + mina;
    	if (Yup > 1){
    		this.removeMovieClip();
    		trace("a death occurred");
    	}
    }
    
    function Growth(){
    	maxc = 1;
    	minc = 0;
    	scaleit = Math.random()*(maxc - minc + 1) + minc;
    	this._xscale = this._xscale + scaleit
    	this._yscale = this._yscale + scaleit
    	trace("The xscale is " + this._xscale);
    }
    
    setInterval(Reproduction, 10000);
    setInterval(Growth, 10000);
    setInterval(Death, 10000);
    I added the traces to see if the functions were being called and they are. Any reference to "this" is undefined.

    Does anybody have any ideas why this is happening?
    I don't have a bad sex life and I have the pictures to prove it.

  7. #7
    Senior Member
    Join Date
    Nov 2004
    Posts
    928
    you need to make a reference to the mc.
    function Reproduction(mc){
    this=mc;
    //rest of you function blah blah

    }

    setInterval(Reproduction, 10000,this);
    and the same for the other functions you have

    or something like that.....

  8. #8
    Board Idiot num97's Avatar
    Join Date
    Jun 2004
    Location
    South of Heaven
    Posts
    194
    That worked. Thanks.
    I don't have a bad sex life and I have the pictures to prove it.

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