I am having trouble adding drag properties to items I load into my Room scrollpane. Additionally, how do I determine what Item I clicked on? I am loading external swf into the Room scrollpane via an XML menu. Ultimately, i would like to add a drag and rotate function, but for now I'll be satisfied just draging the items I add. Everything works except the drag part.
Here is my code, thanks for any help.
ActionScript Code:
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 dValue = this.firstChild.attributes.name;
//trace(dValue);
combo_list.textField.label.text = "Library";
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.Text;
libraryList_ar[i].data = libraries.childNodes[i];
//save reference here
}
}
};
myXML.load("itemMenu.xml");
//
loading_txt.autoSize = true;
loading_txt.text = "";
loading_txt._visible = false;
// resize loading images to thumbnail size
var MAX_WIDTH:Number = 50;
var MAX_HEIGHT:Number = 50;
//
var mcl:MovieClipLoader = new MovieClipLoader();
var mclListener:Object = new Object();
mclListener.onLoadInit = function(mc:MovieClip) {
loading_txt.text = "Loading...";
// set variables to keep the original image dimensions
var xw = mc._width;
var xh = mc._height;
//
// where image width is greater than image height
if (mc._width>mc._height) {
mc._width = MAX_WIDTH;
mc._height = (mc._height*MAX_WIDTH)/xw;
// center image
mc._y = (75-mc._height)/2;
}
//where image height is greater than image width
if (mc._height>mc._width) {
mc._height = MAX_HEIGHT;
mc._width = (mc._width*MAX_HEIGHT)/xh;
mc._x = (75-mc._width)/2;
}
//
loading_txt._visible = false;
};
//
_global.count = 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.Text);
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);
//this loads the swf into the thumbs scrollPane
_root["mc"+idx] = new MovieClipLoader();
_root["mc"+idx].addListener(mclListener);
_root["mc"+idx].loadClip(itemXML.childNodes[idx].attributes.ItemSWF, t_mc.Container_mc);
//_root["mc"+idx].loadClip("decals/"+ItemSWF+".swf", t_mc.Container_mc);
//
t_mc.idx = idx;
t_mc.piece = itemXML.childNodes[idx].attributes.ItemSWF;
//
t_mc.onRelease = function() {
//trace(this.now)
// this adds the item to the room
var tmp:MovieClip = room.content.createEmptyMovieClip("myLoader"+count, count+100);
count++;
mcl.loadClip("decals/"+this.piece+".swf", tmp);
tmp._x = 100;
tmp._y =100;
room.invalidate();
//trace("tmp= "+tmp);
_global.temp_mc = tmp;
};
}
};
combo_list.addEventListener("change", combo_list);
// add draging
room.temp_mc.onPress = function() {
this.startDrag();
};
room.temp_mc.onRelease = function() {
this.stopDrag();
};