Groups | Blog | Home
all groups > flash actionscript > august 2007 >

flash actionscript : Externally loaded SWF X&Y position



jcedens
8/8/2007 9:33:44 PM
I have spent the last 2 hours searching this forum for a solution to my
problem. I have read more than 20 topics and tried them all...nothing works.

My problem:

I have a SWF that uses the following script to load another swf:

loadMovieNum("Base/BASE_ALL.swf",2);

I would like to place the "BASE_ALL.swf" exactly 100pixels below the top edge
of the stage. The "BASE_ALL.swf" is w786 by h503, while my "container.swf" is
w786 by h603.
As you can guess, my problem lies with the fact that, no matter what I try, I
can't force the "BASE_ALL.swf" to load, and re-position itself at _y = 100.
This is very frustrating because I am sure that the answer is simple....

Could anyone help?

(Additional info: The "BASE_ALL.swf" externally loads numerous other SWF files
depending on which buttons the user clicks in the menu - it's a website. All
these files are w786 by h503. The only file that is h603 is the
"container.swf". The "container.swf" is 100px taller in order to allow an area
for a company logo that will remain visible regardless of where the user goes
within the site.)

kglad
8/8/2007 9:40:20 PM
jcedens
8/8/2007 9:44:16 PM
Didn't work (I could have entered it incorrectly though).....

Here is what I have now:

loadMovieNum("Base/BASE_ALL.swf",2);
_level2._x = 0;
_level2._y = 100;

It loads the movie, but the "BASE_ALL.swf" still defaults to the upper left of
the container.swf's stage....

kglad
8/8/2007 11:07:20 PM
you must wait until _level2 exists before you try to control any of its
properties.

if nothing has been loaded into it before the code you posted in your last
message, then you must use preloader code to ensure BASE_ALL.swf has completed
loading before trying to access the _x and _y properties of _level2.
jcedens
8/9/2007 2:58:58 PM
OK,

I have changed my code around to include a preloader for my swf.
The following code is located in layer 1, frame 1 of the container.swf:

-------------------------------------

fscommand("fullscreen","true");

this.createEmptyMovieClip("BASE_ALL", 999);
var my_mcl:MovieClipLoader = new MovieClipLoader();

// Create listener object:
var mclListener:Object = new Object();
mclListener.onLoadError = function(target_mc:MovieClip, errorCode:String,
status:Number) {
trace("Error loading image: " + errorCode + " [" + status + "]");
};
mclListener.onLoadStart = function(target_mc:MovieClip):Void {
trace("onLoadStart: " + target_mc);
};
mclListener.onLoadProgress = function(target_mc:MovieClip,
numBytesLoaded:Number, numBytesTotal:Number):Void {
var numPercentLoaded:Number = numBytesLoaded / numBytesTotal * 100;
trace("onLoadProgress: " + target_mc + " is " + numPercentLoaded + "%
loaded");
};
mclListener.onLoadComplete = function(target_mc:MovieClip, status:Number):Void
{
trace("onLoadComplete: " + target_mc);
};

my_mcl.addListener(mclListener);

my_mcl.loadClip("Base/BASE_ALL.swf", BASE_ALL);

Stage.scaleMode = "noScale";
Stage.align = "M";
Stage.addListener(BASE_ALL);
BASE_ALL._x = 0;
BASE_ALL._y = 100;

stop();

------------------------------------------------------------------------

This all works, except I still can't get the mclip to shift itself, along with
the loaded swf down by the 100 pixels to reveal the logo. (currently, it hugs
the top of the stage, covering up the logo, and exposing 100 pixels of blank
space along the bottom of the container.swf).

What am I missing here????????
kglad
8/9/2007 3:16:17 PM
1. when you're loading into a movieclip (like BASE_ALL) instead of a _level,
you don't need preloader code to ensure the movieclip exists. it exists as
soon as you create it. so, you can assign its _x and _y properties any time
after it's created.

2. what's mclip?
jcedens
8/9/2007 3:23:36 PM
1. Forgive me if I sound like a beginner, but, well...I am. I am trying to load
BASE_ALL.swf into an empty movie clip located in another swf (referred to here
as: container.swf). All the previously posted code exists in the container.swf.
The empty movie clip I created in container.swf is called: BASE_ALL. Since I
created the movie clip by the previously posted code, why doesn't the part work
where I am trying to actually position it (any time after it's created).

BASE_ALL._x = 0;
BASE_ALL._y = 100;

2. mclip is short for movie clip

Thanks for your help....
kglad
8/9/2007 5:21:12 PM
1. the code you posted in your last two messages should work without problem.
BASE_ALL.swf's upper left should be at 0,100.

2. most people using flash use mc as short for movieclip, though even this
can cause confusion unless it's within some context like, "i created an empty
mc".
jcedens
8/9/2007 5:56:11 PM
I know that it SHOULD work....

My question is: Can anyone figure out why it is NOT working?

kglad
8/9/2007 6:39:46 PM
lol. which "the" mc?

it matters where BASE_ALL is positioned, but that shouldn't be changed by
anything other than the script you've posted.

it you think BASE_ALL.swf is NOT loading with its upper left at 0,100, post a
link to your container fla and BASE_ALL.fla.
jcedens
8/9/2007 6:49:33 PM
"the mc" was referring to the dynamically created one...but I see what you're
saying, so nm...

I would love to send it to you, but as far as I know, I have no way of posting
those files to a site for you to download... they are very small though, could
I email them to you?
kglad
8/9/2007 6:52:25 PM
kglad
8/9/2007 7:38:10 PM
if you were loading lines.swf and nav.swf and main.swf into a BASE_ALL.swf,
then positioning BASE_ALL.swf would position those loaded swfs.

but those swfs are not loading into BASE_ALL.swf. they are loading into
_levels. and _levels do not inherit anything from the swf that causes them to
exist.

so, you do need to use preloader code to ensure your _levels exist and when
they do, you can position the _levels.

therefore, in container.swf you can remove all the code except the code that
loads BASE_ALL.swf. and in BASE_ALL.swf you can use:



loadMovieNum("Base/LINES.swf", 19);
loadMovieNum("Base/NAV.swf", 18);
loadMovieNum("Base/MAIN.swf", 3);
preloadI = setInterval(preloadF, 100);

tl = this;
levelA = [3, 18, 19];
finishedLoading = 1;

function preloadF() {
for (var i = 0; i<levelA.length; i++) {
tl["bl"+levelA[i]] = eval("_level"+levelA[i]).getBytesLoaded();
tl["bt"+levelA[i]] = eval("_level"+levelA[i]).getBytesTotal();
if (tl["bl"+levelA[i]]>0 && tl["bl"+levelA[i]] == tl["bt"+levelA[i]]) {
eval("_level"+levelA[i]).completed = 1;
eval("_level"+levelA[i])._y = 100;
}
finishedLoading *= eval("_level"+levelA[i]).completed;
}
if (finishedLoading) {
clearInterval(preloadI);
}
}
stop();
jcedens
8/9/2007 8:00:01 PM
Sweet.
That worked great. Thank you.

However, (there's always a however, right?) if I click on anything in my
nav.swf menu bar, it loads my other content (everything else in the whole site
is w786 by h503 as well) at that top left corner default position.......and, if
i click on main, it loads everything back to that spot as well...

Normally, I could look at that code you posted and tweak it, but it was a
little over my head....(most of the stuff I know at this point came from
studying the built-in help topics in Flash Pro8 - it didn't recognize a lot of
the script that you used)
jcedens
8/10/2007 12:00:00 AM
Ok, after further review, I was able to adapt that script you posted earlier.
The other mc's that are loaded into the BASE_ALL.swf (nav, main, lines) using
levels. All I did was put that script into each subsequent mc (only changing
the target level reference: levelA = [ //targetlevelnumberhere// ]; ) which
places each mc at the ._y = 100 position.

Thanks again for all your help! (that script will answer a lot of questions
about loading swfs into swfs - and trying to position them - that have been
posted here in the past)
kglad
8/10/2007 2:43:09 AM
kglad
8/10/2007 1:58:30 PM
AddThis Social Bookmark Button