added Children but objects not displaying in Flash
I'm adding a series of objects dynamically to my flash movie from xml but they won't appear when I run the movie. I have nearly identical code adding objects in a different swf that works just fine. I have tested this 8 ways from Sunday including ensuring that they were added to the container which is a child of the main MovieClip (tested the display list), that they were added to stage (had a listener for ADDED_TO_STAGE) and that their position was correct (displayed x,y values and compared them to mouseX & mouseY values). They are in the correct place in the display list. Still there are no objects. The class is linked correctly, I have movie clips in the library.
Any ideas what could be causing the problem? I feel like I've checked everything.
'public class MiniMap extends MovieClip {
private var expLoader:LoadXML = new LoadXML("Experiences.xml",true);
public var expList:XMLList;
private var popCont:Sprite = new Sprite();
private var pop:PopUp;
private var expCont:Sprite = new Sprite();
private var pnt:Point;
private var exp:Experiences;
public function MiniMap()
{
// requires mouseup mousedown (pan) and close functions
//must load experiences which will have their own class
popCont.name = "popCont";
expCont.name = "expCont";
expCont.x = 0;
expCont.y = 0;
expCont.visible = true;
expCont.width = 4000;
expCont.height = 3000;
mm.addEventListener(MouseEvent.MOUSE_DOWN, panMap, false, 0, true);
expLoader.addEventListener("xmlLoaded", onLoadexp);
mm.addChild(popCont);
mm.addChildAt(expCont, 2);
}
private function onLoadexp(e:Event):void
{
expList = new XMLList(expLoader.xml.*);
trace(expList.Longitude[1]);
for (var i:int = 0; i < 3; i++)
{
exp = new Experiences(expList.Description[i],expList.Experience_Name[i]);
exp.x = i * 0.5 + 1156;
exp.y = i*0.75 + 1651;
exp.name = expList.Experience_ID[i];
/*exp.x = 1284.3216 * expList.Longitude[i] + 101472.0151;
exp.y = -1744.6503 * expList.Latitude[i] + 80213.7461;*/
exp.titl = expList.Experience_Name[i];
exp.desc = expList.Description[i];
exp.phourl = expList.photo[i];
exp.type = expList.County[i];
switch (exp.type)
{
case "City of Kawartha Lakes" :
exp.gotoAndPlay("Yellow");
break;
case "Peterborough County" :
exp.gotoAndPlay("Green");
break;
case "Northumberland County" :
exp.gotoAndPlay("Blue");
break;
case "Northumberland" :
exp.gotoAndPlay("Red");
break;
开发者_高级运维 }
exp.addEventListener(MouseEvent.CLICK, onExpClick, false,0, true);
exp.addEventListener(Event.ADDED_TO_STAGE, onAdded, false,0, true);
expCont.addChild(exp);
}
trace(expCont.root);
}
private function onExpClick(m:MouseEvent):void
{
//check for other popups
if (popCont.numChildren > 0)
{
closePop();
}
pop = new PopUp(m.target.titl,m.target.desc);
pop.closer.addEventListener(MouseEvent.CLICK, closePop);
mm.popCont.addChild(pop);
}
private function onAdded(e:Event):void
{
trace(e.target.name + " was added to the stage at "+e.target.x + ", " + e.target.y);
}
private function closePop():void {
mm.popCont.removeChildAt(0);
}
private function panMap(m:MouseEvent):void
{
//click and drag to pan the minimap
mm.startDrag();
trace(mouseX+", "+mouseY);
mm.addEventListener(MouseEvent.MOUSE_UP, relsMap, false, 0, true);
}
private function relsMap(m:MouseEvent):void
{
//drops the minimap
mm.stopDrag();
}'
Have you used the addchild()
command once the object have been loaded to flash? You need to add objects to the display list for them to show on the stage (Assuming you are coding in AS3)
http://forums.creativecow.net/thread/190/864240
Looks like here is your problem
exp.x = i * 0.5 + 1156;
exp.y = i*0.75 + 1651;
I don't know what size your swf is but I doubt it can handle these numbers.
Honestly, theres not much to do on this end unless you post some code.
I will say this: If I'm in a situation where something aught to be happening, and isn't, you just have to, very methodically, trace your way back through the logic chain. If your objects aren't showing up on the stage, there is a distinctly limited number of things that could be out of sorts. A short (and incomplete) checklist:
XML - is data being retrieved and parsed correctly? trace out the vars. Library - if you are relying on objects in the library, ensure their linkage names are all correct, and your pathing is correct. Display list - obviously, addChild is essential, but what is your display list order? is there something obscuring your objects? Object props - finally, make sure properties like "scale", "visibility" etc... are all set properly.
And failing all that, take your sequence out of the project, and test the logic with a minimum number of variables. If you test case is working fine, then change the scope of bug hunt...
good luck
精彩评论