Groups | Blog | Home
all groups > flash actionscript > february 2006 >

flash actionscript : Problem with loaded SWF movie


dadofgage
2/21/2006 8:19:08 PM
I have created a main interface swf file and then a number of othe swf files.

I used this code to load each of the other swf files once the proper button
has been clicked.

on (release) {
stopAllSounds();
createEmptyMovieClip("movie_holder", 1);
movie_holder._x = -650;
movie_holder._y = -68;
movie_holder.loadMovie("abilityfirst-introduction.swf");
}

Inside abilityfirst-introduction.swf, I have some navigation that will allow
them to move through that training section.

The problem happens is that now the navigation inside each of the movies does
not work.

Can someone tell me why?
blemmo
2/21/2006 9:03:21 PM
dadofgage
2/21/2006 9:06:21 PM
It is just the code from a sample presentation.

There has been no modification to it - here it is:

// If not defined yet,
if (isLoaded == undefined) {

// Routine to move playhead to a new frame
var updateFrame = function (inc) {

var newFrame = _currentframe + inc;
gotoAndStop(newFrame);

if (_root._currentframe == 1) {
backBtn._alpha = 50;
backBtn.enabled = false;
} else {
backBtn._alpha = 100;
backBtn.enabled = true;
}
if (_root._currentframe == _root._totalframes) {
forwardBtn._alpha = 50;
forwardBtn.enabled = false;
} else {
forwardBtn._alpha = 100;
forwardBtn.enabled = true;
}
}


// When the forward button is pressed
forwardBtn.onPress = function () {
updateFrame(1);
stopAllSounds();
}

// When the back button is pressed
backBtn.onPress = function () {
updateFrame(-1);
stopAllSounds();
}

// When the keyboard keys are pressed
var keyListener = new Object();
keyListener.onKeyDown = function () {
if (Key.isDown(37)) {
// Left
updateFrame(-1);
} else if (Key.isDown(38)) {
// Up
updateFrame(-(_currentframe-1));
} else if (Key.isDown(39)) {
// Right
updateFrame(1);
} else if (Key.isDown(40)) {
// Down
updateFrame(_totalFrames + 1);
}
}
Key.addListener(keyListener);


// Call updateFrame at first to get button states correct at start
updateFrame();
}

// Set loaded flag to prevent redefinition
this.isLoaded = true;
stop();
Chip W.
2/21/2006 9:30:23 PM
Your problem lies in the keyword "_root", which no longer applies to the loaded
movie with the naviagtion, _root now applies to the swf that loaded your
navigation. You loaded your navigation interface movie into a _root level of
another swf, therefore, when targeting _root from your navigation, you are
targeting the _root level of the movie which loaded your navigation. Replacing
_root with _parent is the simple solution, or retarget to
_root.levelAtWhichYourMovieIsLoaded.

Hope that helps a bit,
Chipley
dadofgage
2/21/2006 9:40:42 PM
I tried replacing it _root with _parent - but it did not work.

blemmo
2/21/2006 10:36:18 PM
Try replacing '_root' with 'this' (I assume the navigation should navigate inside the loaded Movie).

cheers,
dadofgage
2/22/2006 12:11:22 AM
Here is the code I am using now.....

// If not defined yet,
if (isLoaded == undefined) {

// Routine to move playhead to a new frame
var updateFrame = function (inc) {

var newFrame = _currentframe + inc;
gotoAndStop(newFrame);

if (this._currentframe == 1) {
backBtn._alpha = 50;
backBtn.enabled = false;
} else {
backBtn._alpha = 100;
backBtn.enabled = true;
}
if (this._currentframe == this._totalframes) {
forwardBtn._alpha = 50;
forwardBtn.enabled = false;
} else {
forwardBtn._alpha = 100;
forwardBtn.enabled = true;
}
}


// When the forward button is pressed
forwardBtn.onPress = function () {
updateFrame(1);
stopAllSounds();
}

// When the back button is pressed
backBtn.onPress = function () {
updateFrame(-1);
stopAllSounds();
}

// When the keyboard keys are pressed
var keyListener = new Object();
keyListener.onKeyDown = function () {
if (Key.isDown(37)) {
// Left
updateFrame(-1);
} else if (Key.isDown(38)) {
// Up
updateFrame(-(_currentframe-1));
} else if (Key.isDown(39)) {
// Right
updateFrame(1);
} else if (Key.isDown(40)) {
// Down
updateFrame(_totalFrames + 1);
}
}
Key.addListener(keyListener);


// Call updateFrame at first to get button states correct at start
updateFrame();
}

// Set loaded flag to prevent redefinition
this.isLoaded = true;
stop();
blemmo
2/22/2006 12:35:41 AM
dadofgage
2/22/2006 12:38:53 AM
It is not, no.

blemmo
2/22/2006 1:28:23 AM
Is nothing working or just parts of it? Please place a trace call inside the
button methods, the keydown method and also one right before the updateFrame
definition, to see if the code gets executed at all. Then test the buttons and
keys to see if any output is produced.
AddThis Social Bookmark Button