A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: [F8] Why does the variable lose definition?

Hybrid View

  1. #1
    Instructional Designer
    Join Date
    Feb 2005
    Location
    Whidbey Island: north of Seattle, east of Victoria, south of Vancouver
    Posts
    299
    Yes. You are right on with that one. I was surprised that typecasting didn't catch my problem. It seems like a throw back to 1.0 where you could change the casting by just making the variable equal some new data type.

    Unfortunately, fixing this problem does not change the problem with goalY and goalX. They remain undefined (I've shown the first few lines of output after implementing the correction to the array value assignment).
    Level #0:
    Variable _level0.$version = "WIN 9,0,45,0"
    Variable _level0.i = 0
    Variable _level0.u = 0
    Variable _level0.goalY = undefined
    Variable _level0.goalX = undefined
    Variable _level0.myXArray = [object #1, class 'Array'] [
    0:0,
    1:-34,
    2:-81,
    3:-128,
    4:-176,
    5:-162,
    6:-223,
    7:-273,
    8:-323
    ]
    Variable _level0.myYArray = [object #2, class 'Array'] [
    0:150,
    1:-264
    ]
    Variable _level0.mc1Listener = [object #3, class 'Object'] {
    onLoadInit:[function 'onLoadInit']
    }
    This may suggest the solution, I just need to ponder this for a few more minutes. I'll let you know as soon as the light comes on.
    Tomas

  2. #2
    Instructional Designer
    Join Date
    Feb 2005
    Location
    Whidbey Island: north of Seattle, east of Victoria, south of Vancouver
    Posts
    299

    Thinking out loud

    Keep in mind that goalX and goalY are typecast as Number. They are initially set to a value of zero. If I run debug: variables, the output shows the value of each defined as zero. But if I click on a button, and then run the variables, the output shows the affected variable as undefined.

    This suggests that the code for the button:

    Code:
    downM.onRelease = function() {
    	_root.goalY = _root.myYArray[i++];//This should set goalY to the value of i++
    	slideY();
    };
    upM.onRelease = function(){
    	_root.goalY = _root.myYArray[i--];
    	slideY();
    };
    rightM.onRelease = function() {
    	_root.goalX = _root.myXArray[u++];
    	slideX();
    };
    leftM.onRelease = function(){
    	_root.goalX = _root.myXArray[u--];
    	slideX();
    };
    Or the code for my slide functions, is causing the problem.

    Code:
    function slideY() {
    	_root.dataFile.onEnterFrame = function() {
    		_root.dataFile.diff = Math.abs(_root.dataFile._y-_root.goalY);
    		if (_root.dataFile.diff<1) {
    			_root.dataFile._y = _root.goalY;
    			_root.head._y = _root.goalY;
    			delete _root.dataFile.onEnterFrame;
    		} else {
    			_root.dataFile._y += (_root.goalY-_root.dataFile._y)*.3;
    			_root.head._y += (_root.goalY-_root.head._y)*.3;
    		}
    	}
    };
    
    function slideX() {
    	_root.dataFile.onEnterFrame = function() {
    		_root.dataFile.diff = Math.abs(_root.dataFile._x-_root.goalX);
    		if (_root.dataFile.diff<1) {
    			_root.dataFile._x = _root.goalX;
    			_root.head._x = _root.goalX;
    			delete _root.dataFile.onEnterFrame;
    		} else {
    			_root.dataFile._x += (_root.goalX-_root.dataFile._x)*.3;
    			_root.head._x += (_root.goalX-_root.head._x)*.3;
    		}
    	}
    };
    Tomas

  3. #3
    Instructional Designer
    Join Date
    Feb 2005
    Location
    Whidbey Island: north of Seattle, east of Victoria, south of Vancouver
    Posts
    299
    This was one of those stupidly confident leaps of faith. I declared my arrays and at the same time set them to equal the value of the variable (u, i). I wonder if this is a source of problem? (Probably not, since the array does not show a problem in the debug output.)

    Code:
    var myXArray:Array = new Array;
    myXArray=[u];
    var myYArray:Array = new Array;
    myYArray=[i];
    This seems logical, but I have learned to doubt that basis.
    Tomas

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