PDA

View Full Version : loadMovie-duplicateMovie help


Navarone
09-06-2006, 01:13 PM
I am having items load into a scrollPane I call thumbs, when I click on one of my images in the scrollPane, I want to load a swf into another scrollPane I call room.

I have been able to accomplish this somewhat but I need some help on how to add another instance of the swf to the same room. If I click on my thumb all it does is replace the loaded swf. I don't know if duplicateMovie is the correct approach or not, so I could use some advise here.

What is the best way to add additional instances of the same swf? This is my onRelease function that loads the swf.

t_mc.onRelease = function() {
trace(this)
//trace(this.location);
//room.content.myLoader.contentPath = this.now+".swf";
room.content.myLoader.loadMovie(this.now+".swf", this.getNextHighestDepth());
room.content.myLoader._x = 100;
room.content.myLoader._y = 100;
room.invalidate();
//
};


and this is all of my code so far,


var myXML:XML = new XML();
myXML.ignoreWhite = true;
libraryList_ar = new Array();
combo_list.dataProvider = libraryList_ar;
myXML.onLoad = function(success) {
if (success) {
//trace(this);
var libraries = this.firstChild;
var libCount = libraries.childNodes.length;
trace(libCount);
var libItems = libraries.firstChild.childNodes.length;
trace(libItems);
//
for (var i = 0; i<libCount; i++) {
//libraryList_ar[i] = libraries.childNodes[i].childNodes[0].firstChild.nodeValue;
libraryList_ar[i] = new Object();
libraryList_ar[i].label = libraries.childNodes[i].attributes.name;
libraryList_ar[i].data = libraries.childNodes[i];
//save reference here
}
}
};
myXML.load("myXML.xml");
//
combo_list.change = function(eventObj) {
thumbs.invalidate();
thumbs.refreshPane();
//
var selItem:Object = eventObj.target.selectedItem;
trace("Item selected was: "+selItem.label);
var itemXML:XMLNode = selItem.data;
//use saved reference to iterate through childNodes
for (var idx = 0; idx<itemXML.childNodes.length; idx++) {
trace("Item includes: "+itemXML.childNodes[idx].attributes.source);
var t_mc:MovieClip;
//t_mc = thumbs.content.attachMovie("thumb_mc", "thumb"+idx, idx, this.getNextHighestDepth());
t_mc = thumbs.content.attachMovie("thumb_mc", "thumb"+idx, idx, this.getNextHighestDepth());
t_mc._x = 5;
t_mc._y = 5+(idx*80);
t_mc.idx = idx;
t_mc.now = itemXML.childNodes[idx].attributes.source;
trace(t_mc.idx);
//
t_mc.onRelease = function() {
trace(this)
//trace(this.location);
//room.content.myLoader.contentPath = this.now+".swf";
room.content.myLoader.loadMovie(this.now+".swf", this.getNextHighestDepth());
room.content.myLoader._x = 100;
room.content.myLoader._y = 100;
room.invalidate();
//
};
}
};
combo_list.addEventListener("change", combo_list);
//

Kraken
09-06-2006, 04:35 PM
loadMovie will always overload whatever MC you specify. What you should do is create a new MC each time you want to add and not replace. So, something like this:

t_mc.onRelease = function() {
trace(this)
//trace(this.location);
//room.content.myLoader.contentPath = this.now+".swf";
var tmp:MovieClip = room.content.createEmptyMovieClip("myLoader" + count,room.getNextHighestDepth());
count ++;
tmp.loadMovie(this.now+".swf");
tmp._x = 100;
tmp._y = 100;
room.invalidate();
//
};


Now, you'd have to have a "count" variable that would start at 0 and count up each time a button is pressed to add another empty MC to room before loading something into it.

I would also recommend using the MovieClipLoader class to load your movies and keep track of events.

Navarone
09-06-2006, 05:07 PM
thanks for the help. I don't understand about the count and movieclipLoader. If I set the count=0, and use a for loop or while loop, it doesn't seem to work.
This movieCliploader is that like a listner object?

Kraken
09-06-2006, 05:30 PM
The MovieClipLoader is an object. It's an entirely separate class that simply keeps track of loading external files. You use a listener object to listen to its events and react accordingly. For example:

import mx.transitions.Tween;
import mx.transitions.easing.*;

var myTween:Tween;

var mcl:MovieClipLoader = new MovieClipLoader();

var myListener:Object = {};
myListener.onLoadInit = function(target_mc:MovieClip) {
trace("I'm loaded: " + target_mc);
myTween = new Tween(target_mc,"_alpha",Regular.easeOut,0,100,1,true);
}
mcl.addListener(myListener);

var m:MovieClip = this.createEmptyMovieClip("my_holder_mc",20);

myListener.loadClip("external.swf",m);


Now, as to how to use the count variable, I usually declare it on the main timeline and just increment it from there. But, you'd only need it to be incremented when a button is clicked, so, don't change it in the for loop, just do it like this:

var count:Number = 0;

combo_list.change = function(eventObj) {
thumbs.invalidate();
thumbs.refreshPane();
//
var selItem:Object = eventObj.target.selectedItem;
trace("Item selected was: "+selItem.label);
var itemXML:XMLNode = selItem.data;
//use saved reference to iterate through childNodes
for (var idx = 0; idx<itemXML.childNodes.length; idx++) {
trace("Item includes: "+itemXML.childNodes[idx].attributes.source);
var t_mc:MovieClip;
//t_mc = thumbs.content.attachMovie("thumb_mc", "thumb"+idx, idx, this.getNextHighestDepth());
t_mc = thumbs.content.attachMovie("thumb_mc", "thumb"+idx, idx, this.getNextHighestDepth());
t_mc._x = 5;
t_mc._y = 5+(idx*80);
t_mc.idx = idx;
t_mc.now = itemXML.childNodes[idx].attributes.source;
trace(t_mc.idx);
//
t_mc.onRelease = function() {
trace(this);
//trace(this.location);
//room.content.myLoader.contentPath = this.now+".swf";
var tmp:MovieClip = room.content.createEmptyMovieClip("myLoader" + count,room.getNextHighestDepth());
count ++;
tmp.loadMovie(this.now+".swf");
tmp._x = 100;
tmp._y = 100;
room.invalidate();
//
};
}
};

Navarone
09-06-2006, 07:04 PM
I think I am getting pretty close, what is happening now is when I click my button two movieClips of the same thing appear. One of them is in the room scrollPane and one is out side. If I click my thumb image again, it just wipes out the first and adds 2 new ones. :)


//
var mclListener:Object = new Object();
mclListener.onLoadInit = function(mc:MovieClip) {
loading_txt.text = "Loading...";
};
//
var count:Number = 0;
combo_list.change = function(eventObj) {
thumbs.invalidate();
thumbs.refreshPane();
//
var selItem:Object = eventObj.target.selectedItem;
trace("Item selected was: "+selItem.label);
var itemXML:XMLNode = selItem.data;
//use saved reference to iterate through childNodes
for (var idx = 0; idx<itemXML.childNodes.length; idx++) {
trace("Item includes: "+itemXML.childNodes[idx].attributes.source);
var t_mc:MovieClip;
//t_mc = thumbs.content.attachMovie("thumb_mc", "thumb"+idx, idx, this.getNextHighestDepth());
t_mc = thumbs.content.attachMovie("thumb_mc", "thumb"+idx, idx, this.getNextHighestDepth());
t_mc._x = 5;
t_mc._y = 5+(idx*80);
t_mc.idx = idx;
t_mc.now = itemXML.childNodes[idx].attributes.source;
trace(t_mc.idx);
//
t_mc.onRelease = function() {
var tmp:MovieClip = room.content.createEmptyMovieClip("myLoader"+count, room.getNextHighestDepth());
count++;
//
_root["myLoader"+count] = new MovieClipLoader();
_root["myLoader"+count].addListener(mclListener);
_root["myLoader"+count].loadClip(this.now+".swf", room.getNextHighestDepth());
//
tmp.loadMovie(this.now+".swf");
tmp._x = 100;
tmp._y = 100;
room.invalidate();
trace(count);
//
};
}
};
combo_list.addEventListener("change", combo_list);
//

Kraken
09-06-2006, 07:24 PM
ah! You don't need the loadMovie if you're using the MovieClipLoader to load your SWFs.

Oh, and you don't need more than one MovieClipLoader class, just use the same one to target a different MC. So:

var mcl:MovieClipLoader = new MovieClipLoader();

var mclListener:Object = new Object();
mclListener.onLoadInit = function(mc:MovieClip) {
loading_txt.text = "Loading...";
};
var count:Number = 0;
combo_list.change = function(eventObj) {
thumbs.invalidate();
thumbs.refreshPane();
//
var selItem:Object = eventObj.target.selectedItem;
trace("Item selected was: "+selItem.label);
var itemXML:XMLNode = selItem.data;
//use saved reference to iterate through childNodes
for (var idx = 0; idx<itemXML.childNodes.length; idx++) {
trace("Item includes: "+itemXML.childNodes[idx].attributes.source);
var t_mc:MovieClip;
//t_mc = thumbs.content.attachMovie("thumb_mc", "thumb"+idx, idx, this.getNextHighestDepth());
t_mc = thumbs.content.attachMovie("thumb_mc", "thumb"+idx, idx, this.getNextHighestDepth());
t_mc._x = 5;
t_mc._y = 5+(idx*80);
t_mc.idx = idx;
t_mc.now = itemXML.childNodes[idx].attributes.source;
trace(t_mc.idx);
//
t_mc.onRelease = function() {
var tmp:MovieClip = room.content.createEmptyMovieClip("myLoader"+count, room.getNextHighestDepth());
count++;
//
mcl.loadClip(this.now+".swf", tmp);
tmp._x = 100;
tmp._y = 100;
room.invalidate();
trace(count);
//
};
}
};
combo_list.addEventListener("change", combo_list);

Navarone
09-06-2006, 07:38 PM
ok, I followed your suggestion and changed my code, everything seems to be counting correctly but only one swf ever gets added to the room. :)

Kraken
09-06-2006, 07:46 PM
hmm...oh, are you using a component? I believe there's a problem with the components and using getNextHighestDepth...just a sec...

hmm...couldn't find the issue I was looking for...try using this instead of the createEmptyMovieClip above:

var tmp:MovieClip = room.content.createEmptyMovieClip("myLoader"+count, count + 100);

Navarone
09-06-2006, 07:47 PM
Yeh, I am using the ScrollPane component. let me try your suggestion and I'll get back to you.

Navarone
09-06-2006, 07:51 PM
Yeh it works! This is awsome:D

Thanks for your help Kraken:)

Navarone
09-07-2006, 12:07 PM
kraken

I have a follow up question. Once an item is added to the room, in this case I can trace tmp which gives me

tmp= _level0.room.spContentHolder.myLoader0

How would I remove this item using the removeMovieClip property? Ideally I was thinking i could use the delete key.

would you have something like this:

var keyListener:Object = new Object();
keyListener.onKeyDown = function() {
trace("DOWN -> Code: "+Key.getCode()+"\tACSII: "+Key.getAscii()+"\tKey: "+chr(Key.getAscii()));
if (Key.isDown(46)) {
trace("delete key");
//removeMovieClip()
}
};
Key.addListener(keyListener);

Kraken
09-08-2006, 02:33 AM
well, since count keeps track of how many items you have, you could use that to remove the most recent:
room. spContentHolder["myLoader" + count].removeMovieClip();

but, don't forget to decrease count by one, also:

count --;

Navarone
09-11-2006, 12:24 PM
Ok, I must not be doing this correctly becuase when I click on an item in my room nothing is happening.


var count:Number = 0;
combo_list.change = function(eventObj) {
thumbs.invalidate();
thumbs.refreshPane();
//
var selItem:Object = eventObj.target.selectedItem;
//trace("Item selected was: "+selItem.label);
var itemXML:XMLNode = selItem.data;
//use saved reference to iterate through childNodes
for (var idx = 0; idx<itemXML.childNodes.length; idx++) {
//trace("Item includes: "+itemXML.childNodes[idx].attributes.source);
var t_mc:MovieClip;
t_mc = thumbs.content.attachMovie("thumb_mc", "thumb"+idx, idx, this.getNextHighestDepth());
t_mc._x = 5;
t_mc._y = 5+(idx*80);
t_mc.idx = idx;
t_mc.now = itemXML.childNodes[idx].attributes.source;
//trace(t_mc.idx);
//
t_mc.onRelease = function() {
//trace(this.now)
//var tmp:MovieClip = room.content.createEmptyMovieClip("myLoader"+count, room.getNextHighestDepth());
var tmp:MovieClip = room.content.createEmptyMovieClip("myLoader"+count, count+100);
count++;
mcl.loadClip(this.now+".swf", tmp);
tmp._x = 100;
tmp._y = 100;
room.invalidate();
trace("tmp= "+tmp);
_global.temp_mc = tmp;
};
}
};
combo_list.addEventListener("change", combo_list);
//
temp_mc.onPress = function() {
trace("me");
room.spContentHolder["myLoader"+count].removeMovieClip();
count--;
};

Kraken
09-11-2006, 01:56 PM
Hmm, try it in a browser both locally and on the server. Any error messages? Throw some trace actions in there and see if that will help you find where its broken.

If all that fails, you'll have to post a sample FLA. I'm betting its something to do with the structure and scope of functions.

Navarone
09-11-2006, 02:05 PM
I messed around with it some more and finally came up with this

room.content.onPress = function() {
trace(temp_mc);
room.spContentHolder["myLoader"+count].removeMovieClip();
count--;
};


however, this onPress function nullifies the freeTransform tool (http://proto.layer51.com/d.aspx?f=636) I am trying to use.

I am not really clear on why this is. This is a movieClip prototype created by senocular. So I may post a seperate thread for some help on this issue.

Navarone
09-11-2006, 03:40 PM
well so far no luck. I bundled everything into a zip file(see attached) This is a Flash MX 2004 Prof file. This is what I have been working with. The only items that work are tables and chairs. Any help or coments are welcomed.:)