Groups | Blog | Home
all groups > flash actionscript > december 2005 >

flash actionscript : Movie Clip Loader


Vee
12/18/2005 7:28:43 PM
I was playing around with the AS2.0 dictionary and trying to get used to using
mcLoader to load external SWFs into mc and ran into a problem. I can get
everything to load correctly from an onRelease function:
Code:
target_mc = MovieClip;
numBytesLoaded = Number;
numBytesTotal = Number;
errorCode = String;
btn_1.onRelease = function() {
content_mc._x = 68.5;
//
var my_mcl:MovieClipLoader = new MovieClipLoader();
// Create listener object:
var mclListener:Object = new Object();
mclListener.onLoadError = function(target_mc, errorCode,
status:Number) {
trace("Error loading image: "+errorCode+" ["+status+"]");
};
mclListener.onLoadStart = function(target_mc):Void {
trace("onLoadStart: "+target_mc);
};
mclListener.onLoadProgress = function(target_mc, numBytesLoaded,
numBytesTotal):Void {
var numPercentLoaded:Number = numBytesLoaded/numBytesTotal*100;
trace("onLoadProgress: "+target_mc+" is "+numPercentLoaded+"%
loaded");
numPercent = numPercentLoaded;
};
mclListener.onLoadComplete = function(target_mc, status:Number):Void {
trace("onLoadComplete: "+target_mc);
menu_1.gotoAndStop("loadedSWF");
};}

I want to display the results of numPercentLoaded in an dy.text box thats
located inside a mc (not the one that the swf is being loaded into but another)
named menu_mc (located on the root timeline). Im having trouble targeting it. I
know I can't put global in front of that type. The who thing traces just fine
and I can even get the dynamic text box to display the numPercentLoaded is its
located on the _root but not if its embedded into menu_mc.
Motion Maker
12/18/2005 9:05:31 PM
Use an absolute path from the _root. Ex:

_root.textContainer_mc.text_txt.text = numPercentLoaded;

--
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
I was playing around with the AS2.0 dictionary and trying to get used to
using
mcLoader to load external SWFs into mc and ran into a problem. I can get
everything to load correctly from an onRelease function:
Code:
target_mc = MovieClip;
numBytesLoaded = Number;
numBytesTotal = Number;
errorCode = String;
btn_1.onRelease = function() {
content_mc._x = 68.5;
//
var my_mcl:MovieClipLoader = new MovieClipLoader();
// Create listener object:
var mclListener:Object = new Object();
mclListener.onLoadError = function(target_mc, errorCode,
status:Number) {
trace("Error loading image: "+errorCode+" ["+status+"]");
};
mclListener.onLoadStart = function(target_mc):Void {
trace("onLoadStart: "+target_mc);
};
mclListener.onLoadProgress = function(target_mc, numBytesLoaded,
numBytesTotal):Void {
var numPercentLoaded:Number =
numBytesLoaded/numBytesTotal*100;
trace("onLoadProgress: "+target_mc+" is
"+numPercentLoaded+"%
loaded");
numPercent = numPercentLoaded;
};
mclListener.onLoadComplete = function(target_mc,
status:Number):Void {
trace("onLoadComplete: "+target_mc);
menu_1.gotoAndStop("loadedSWF");
};}

I want to display the results of numPercentLoaded in an dy.text box thats
located inside a mc (not the one that the swf is being loaded into but
another)
named menu_mc (located on the root timeline). Im having trouble targeting
it. I
know I can't put global in front of that type. The who thing traces just
fine
and I can even get the dynamic text box to display the numPercentLoaded is
its
located on the _root but not if its embedded into menu_mc.

Motion Maker
12/19/2005 2:15:44 AM
More ideas
1.
[quoted text, click to view]
I guess I am not sure if you are using the old method of associating a
variable with a text field using the properties window var field.
If you are then the above line would work if you had a dynamic text field on
the _root.menu_1 timeline and that text field is associated with the
variable numPercent. It also assumes numPercentLoaded is valid.

Personally I prefer to give the dynamic text fields an instance name ( the
newer way) and use the text property to update them. In this case it would
be if the dynamic text field was named myTf_txt.
_root.menu_1.myTf_txt.text = numPercentLoaded;

2.
If the onRelease is declaring variables (you use var) then those variables
are destroyed when onRelease ends.

--
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
myIP
When I create this text dy. text box on the _root timeline with an assigned
variable name of numPercent, everyhthing works fine. Then when I try to use
the same dy. text box inside an mc (menu_1) located on the _root timeline I
cant seem to target it.
Newsgroup User

Motion Maker
I used your code on and replaced the instance names like such:
_root.menu_1.numPercent = numPercentLoaded;
// menu_1 on root timeline
// numPercent is the dy. text box
I put this on the root timeline before my button code and inside the
OnRelease
statement inside the mclListener.onLoadProgress = function and still no
results. I also put this inside menu_1 and got no results as well:
numPercent = _root.numPercentLoaded.text;

Thank for trying to help so far everyone. If you have anything else I
should
try or point out what im doing wrong that would be great.

Vee
12/19/2005 3:16:52 AM
myIP
When I create this text dy. text box on the _root timeline with an assigned
variable name of numPercent, everyhthing works fine. Then when I try to use
the same dy. text box inside an mc (menu_1) located on the _root timeline I
cant seem to target it.
Newsgroup User

Motion Maker
I used your code on and replaced the instance names like such:
_root.menu_1.numPercent = numPercentLoaded;
// menu_1 on root timeline
// numPercent is the dy. text box
I put this on the root timeline before my button code and inside the OnRelease
statement inside the mclListener.onLoadProgress = function and still no
results. I also put this inside menu_1 and got no results as well:
numPercent = _root.numPercentLoaded.text;

Thank for trying to help so far everyone. If you have anything else I should
try or point out what im doing wrong that would be great.

Motion Maker
12/19/2005 11:43:08 AM
Hope I am not taking you in too deep or off course but I think you can have
one MovieCLipLoader. Place the code in a function and call it from the menu
movieclips passing the menu movieclip reference as an argument. Here is the
idea:

// For the menu buttons.
menu_1.menuName.onRelease = function()
{
// I am assuming menuName is a button or movieclip inside of menu_1?????
// The absolute pathe is _root.menu_1.menuName
// and you want to pass _root.menu_1 without an absolute reference
_root.loader(_parent) // Like menuName/.. and would be menu_1
}

//For the code initialization _root frame usually frame 1
//=====================================================
var my_mcl:MovieClipLoader = new MovieClipLoader();
// Create listener object:
var mclListener:Object = new Object();

loader = function (menu_mc)
{
mclListener.menu_mc = menu_mc // <<<<=======================
mclListener.onLoadError = function(target_mc, errorCode, status:Number)
{
trace("Error loading image: " + errorCode + " [" + status + "]");
};
mclListener.onLoadStart = function(target_mc):Void
{
trace("onLoadStart: " + target_mc);
};
mclListener.onLoadProgress = function(target_mc, numBytesLoaded,
numBytesTotal):Void
{
var numPercentLoaded:Number = numBytesLoaded / numBytesTotal * 100;
trace("onLoadProgress: " + target_mc + " is " + numPercentLoaded + "%
loaded");
this.menu_mc.numPercent = numPercentLoaded; // <<<<=======================
//_root.side_menu_1.numPercent = numPercentLoaded;
//numPercent = Math.round(numPercentLoaded)+"%";
};
mclListener.onLoadComplete = function(target_mc, status:Number):Void
{
trace("onLoadComplete: " + target_mc);
side_menu_1.gotoAndStop("loadedSWF");
};
my_mcl.addListener(mclListener);
my_mcl.loadClip("whatever1.swf", content_mc);
// un/load subNav button content
unloadSide();

}


--
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]

Vee
12/19/2005 4:19:05 PM
Thanks for writing back. The original variable is declared within the
onrelease function. I have about 4 buttons that use the same
listener.MC.Loader. All four load diff. swfs. I guess if I knew how to make a
generic MC. loader i could do it the first way described. I just figured that
would have been more involved to ask originally. Now I guess to solve this
there is no other way...

target_mc = MovieClip;
numBytesLoaded = Number;
numBytesTotal = Number;
errorCode = String;
// buttonMC code
menu_1.menuName.onRelease = function() {
content_mc._x = 68.5;
//
var my_mcl:MovieClipLoader = new MovieClipLoader();
// Create listener object:
var mclListener:Object = new Object();
mclListener.onLoadError = function(target_mc, errorCode, status:Number) {
trace("Error loading image: "+errorCode+" ["+status+"]");
};
mclListener.onLoadStart = function(target_mc):Void {
trace("onLoadStart: "+target_mc);
};
mclListener.onLoadProgress = function(target_mc, numBytesLoaded,
numBytesTotal):Void {
var numPercentLoaded:Number = numBytesLoaded/numBytesTotal*100;
trace("onLoadProgress: "+target_mc+" is "+numPercentLoaded+"% loaded");
_root.side_menu_1.numPercent = numPercentLoaded;
//numPercent = Math.round(numPercentLoaded)+"%";
};
mclListener.onLoadComplete = function(target_mc, status:Number):Void {
trace("onLoadComplete: "+target_mc);
side_menu_1.gotoAndStop("loadedSWF");
};
my_mcl.addListener(mclListener);
my_mcl.loadClip("whatever1.swf", content_mc);
// un/load subNav button content
unloadSide();
}}
Vee
12/20/2005 3:04:51 AM
I GOT IT!
heres the code:
Put this in frame 1
function MCloader(extFile, target_mc) {
var mclLoader:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadError = function(mc) {
MCpreloader.message_txt.text = "Error";
};
mclListener.onLoadStart = function(target_mc):Void {
trace("onLoadStart: "+target_mc);
MCpreloader.message_txt.text = "onLoadStart: "+target_mc+"starting";
};
mclListener.onLoadProgress = function(mc, loadedBytes, totalBytes) {
MCpreloader.message_txt.text = Math.floor(loadedBytes/totalBytes*100)+"%";
};
mclListener.onLoadComplete = function(mc) {
MCpreloader.message_txt.text = "content loaded";
};
mclLoader.addListener(mclListener);
mclLoader.loadClip(extFile, target_mc);
}
on a button
on (release) {
MCloader("someExt.swf", theClip);
}
So im not sure its all AS 2.0 comp. but it works. Thank you everyone for your
help. If you have anything to add to this Im all ears.

Best
Vee

Motion Maker
12/20/2005 10:41:49 AM
[quoted text, click to view]
Super!

[quoted text, click to view]

It is.

--
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
I GOT IT!
heres the code:
Put this in frame 1
function MCloader(extFile, target_mc) {
var mclLoader:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadError = function(mc) {
MCpreloader.message_txt.text = "Error";
};
mclListener.onLoadStart = function(target_mc):Void {
trace("onLoadStart: "+target_mc);
MCpreloader.message_txt.text = "onLoadStart: "+target_mc+"starting";
};
mclListener.onLoadProgress = function(mc, loadedBytes, totalBytes) {
MCpreloader.message_txt.text = Math.floor(loadedBytes/totalBytes*100)+"%";
};
mclListener.onLoadComplete = function(mc) {
MCpreloader.message_txt.text = "content loaded";
};
mclLoader.addListener(mclListener);
mclLoader.loadClip(extFile, target_mc);
}
on a button
on (release) {
MCloader("someExt.swf", theClip);
}
So im not sure its all AS 2.0 comp. but it works. Thank you everyone for
your
help. If you have anything to add to this Im all ears.

Best
Vee

Vee
12/20/2005 4:44:36 PM
AddThis Social Bookmark Button