|
|
|
#1 |
|
Instructional Designer
Join Date: Feb 2005
Location: Whidbey Island: north of Seattle, east of Victoria, south of Vancouver
Posts: 297
|
[F8] Why does the variable lose definition?
I done tried and tried to fix this thing, but for some reason, activating my navigation renders my reference variables (goalX and goalY) “undefined.” I would post these files, but they have confidential data. If necessary, I can replace the bmps with garbage. Hopefully, if I give the code and the debug output, someone can crack this puzzle.
There are four containers holding SWFs in this movie. One container (nav) holds the navigation, another (dataFile) holds an Excel spreadsheet bmp (this SWF delivers the values for the x and y arrays), another (head) holds the column headings, and a forth container holds tab buttons. The nav container includes navigation with four buttons, one for each direction. An _root array for x and another for y holds the various positions for head and dataFile (loaded from the dataFile container) . Here is the _root code: Code:
var i:Number = 0;
var u:Number = 0;
var goalY:Number = 150;
var goalX:Number = 0;
var myXArray:Array = new Array;
myXArray=[u];
var myYArray:Array = new Array;
myYArray=[i];
nav._alpha=35;
nav.onRollOver=function(){
nav._alpha=100;
};
nav.onRollOut=function(){
nav._alpha=25;
};
//Loading the first container++++++++++++++++++++++++++++++++++++++++++++++++++
this.createEmptyMovieClip("dataFile", this.getNextHighestDepth());
var mc1Listener:Object = new Object();
mc1Listener.onLoadInit = function(_loadedMC1:MovieClip) {
if (_loadedMC1 == _root.dataFile){
_loadedMC1._x = 0;
_loadedMC1._y = 150;
trace(dataFile._y);
}else{
trace("I'm afraid _loadedMC1 didn't load, or is not defined!" + _loadedMC1);
}
};
var MCdata:MovieClipLoader = new MovieClipLoader();
MCdata.addListener(mc1Listener);
MCdata.loadClip("Summary.swf",this.dataFile);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Loading the second container++++++++++++++++++++++++++++++++++++=
this.createEmptyMovieClip("head", this.getNextHighestDepth());
var mc2Listener:Object = new Object();
mc2Listener.onLoadInit = function(_loadedMC2:MovieClip) {
if (_loadedMC2 == _root.head){
_loadedMC2._x = 0;
_loadedMC2._y = 0;
}else{
trace("I'm afraid _loadedMC2 didn't load, or is not defined!" + _loadedMC2);
}
};
var mcHead:MovieClipLoader = new MovieClipLoader();
mcHead.addListener(mc2Listener);
mcHead.loadClip("SummaryHead.swf",this.head);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Loading the third container++++++++++++++++++++++++++++++++++++=
this.createEmptyMovieClip("tabs", this.getNextHighestDepth());
var mc3Listener:Object = new Object();
mc3Listener.onLoadInit = function(_loadedMC3:MovieClip) {
if (_loadedMC3 == _root.tabs){
_loadedMC3._x = 0;
_loadedMC3._y = 514;
}else{
trace("I'm afraid _loadedMC3 didn't load, or is not defined!" + _loadedMC3);
}
};
var mcTabs:MovieClipLoader = new MovieClipLoader();
mcTabs.addListener(mc3Listener);
mcTabs.loadClip("TabControl.swf",this.tabs);
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//Loading the forth container++++++++++++++++++++++++++++++++++++=
this.createEmptyMovieClip("nav", this.getNextHighestDepth());
var mc4Listener:Object = new Object();
mc4Listener.onLoadInit = function(_loadedMC4:MovieClip) {
if (_loadedMC4 == _root.nav){
_loadedMC4._x = 300;
_loadedMC4._y = 20;
//_loadedMC4.swapDepths(_root.getNextHighestDepth());
}else{
trace("I'm afraid _loadedMC4 didn't load, or is not defined!" + _loadedMC4);
}
};
var mcNav:MovieClipLoader = new MovieClipLoader();
mcNav.addListener(mc4Listener);
mcNav.loadClip("NavController.swf",this.nav);
Code:
Stage.align="TL"; _root.myXArray=(0, -34, -81, -128, -176, -162, -223, -273, -323); _root.myYArray=(150, -264); Code:
//This file loads to one of four containers on the main timeline. This file allows the user
//to move the dataFile container holding the spreadsheet data rows. The onEnterFrame function
// references a root an array on a file loaded to the dataFile container. Each time the user
//click an arrow, the variable for array position changes the goalY or goalX variable on the main timeline.
//These two variables control the scroll functionality for both the dataFile and the head containers.
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;
}
}
};
//These functions set the goal variables and activates scrolling (above)
downM.onRelease = function() {
_root.myYArray[i++];
_root.goalY = myYArray;
slideY();
};
upM.onRelease = function(){
_root.myYArray[i--];
_root.goalY = myYArray;
slideY();
};
rightM.onRelease = function() {
_root.goalX = _root.myXArray[u++];
slideX();
};
leftM.onRelease = function(){
_root.goalX = _root.myXArray[u--];
slideX();
};
//These functions animate the arrows to give the user notice of function
//I initially nested this code with the arrows symbol, but there was some
//conflict preventing that from working. Instead of figuring it out, just moved
//them to this timeline. The negative: 8 functions instead of 2. The positive: this works.
leftM.onRollOver=function(){
leftM.play();
}
leftM.onRollOut=function(){
leftM.gotoAndStop("home");
}
rightM.onRollOver=function(){
rightM.play();
}
rightM.onRollOut=function(){
rightM.gotoAndStop("home");
}
upM.onRollOver=function(){
upM.play();
}
upM.onRollOut=function(){
upM.gotoAndStop("home");
}
downM.onRollOver=function(){
downM.play();
}
downM.onRollOut=function(){
downM.gotoAndStop("home");
}
I have attached the debug output after I’ve clicked on the buttons. Obviously, the containers do not move as intended. But why?
__________________
Tomas Last edited by Thomas D.Garrod; 10-21-2007 at 01:34 PM. |
|
|
|
|
|
#2 |
|
FK'n_dog
Join Date: Apr 2003
Location: "aaarf"
Posts: 9,176
|
in you root code you declare your array -
PHP Code:
PHP Code:
PHP Code:
PHP Code:
Last edited by a_modified_dog; 08-24-2007 at 12:25 AM. Reason: see edit :) |
|
|
|
|
|
#3 | |
|
Instructional Designer
Join Date: Feb 2005
Location: Whidbey Island: north of Seattle, east of Victoria, south of Vancouver
Posts: 297
|
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). Quote:
__________________
Tomas |
|
|
|
|
|
|
#4 |
|
Instructional Designer
Join Date: Feb 2005
Location: Whidbey Island: north of Seattle, east of Victoria, south of Vancouver
Posts: 297
|
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();
};
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 |
|
|
|
|
|
#5 |
|
Instructional Designer
Join Date: Feb 2005
Location: Whidbey Island: north of Seattle, east of Victoria, south of Vancouver
Posts: 297
|
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];
__________________
Tomas |
|
|
|
|
|
#6 |
|
:
Join Date: Dec 2002
Posts: 2,557
|
Maybe try something like this...
Code:
downM.onRelease = function() {
_root.goalY = _root.myYArray[_root.i++];
slideY();
};
upM.onRelease = function(){
_root.goalY = _root.myYArray[_root.i--];
slideY();
};
rightM.onRelease = function() {
_root.goalX = _root.myXArray[_root.u++];
slideX();
};
leftM.onRelease = function(){
_root.goalX = _root.myXArray[_root.u--];
slideX();
};
|
|
|
|
|
|
#7 |
|
FK'n_dog
Join Date: Apr 2003
Location: "aaarf"
Posts: 9,176
|
or break it down even further to check the logic -
PHP Code:
|
|
|
|
|
|
#8 |
|
Instructional Designer
Join Date: Feb 2005
Location: Whidbey Island: north of Seattle, east of Victoria, south of Vancouver
Posts: 297
|
dawsonk's tip was right-on. Adding _root to the u and i, made the difference. Now I need to fix the lack of limits. The scrolling worked initially and then erratcally, then not at all. Debug showed that the index was at a negative position.
But this is progress! Dog, you are quite right to provide debug guidance. These tips are greatly appreciated (I want to catch my own fish).
__________________
Tomas |
|
|
|
![]() |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|