Jump to content
Search Community

Gray box problem

Handycam test
Moderator Tag

Recommended Posts

I tried to follow the earlier post on this, and got close, but I am confounded now. Here's what I have been doing:

 

1. I add the items in the first place to my TM Manager by getting something selected in a List when the add button is clicked. I set the instance's name based on an XML node of the selected item, which works fine.

protected function addNewItem(obj:Object):void {
var stageItem:AddedItem = new AddedItem();
stageItem.source = "/ttest/images/full/"+obj.img;
stageItem.itemName = obj.name;
stageItem.name = obj.name;
var centerLine:Number = workspace.width/2;
stageItem.x = centerLine - 100;
stageItem.y = 200;

myManager.addItem(stageItem);
}

 

To save the XML, I do the following:

protected function saveBtn_clickHandler(event:MouseEvent):void {
var saveData:XML = new XML();
saveData = myManager.exportFullXML();
var objSend:Object = new Object();
var dataString:String = saveData.toXMLString()
objSend.data = dataString;
objSend.filename = filename;
objSend.userid = userid;
sendData.send(objSend);
}

 

which saves this:







 

and my stage looks like this:

20110207-8uu5efur9p5b795usffmre6eh9.jpg

 

So now I load my xml, using an http service, and it loads like the data that was saved. I loop through this loaded xmllist and get all the "name" attributes. Then, I compare these names in a loop against the loop of all the items in all my lists to get the matches, which seems to work. Then I am trying to add each item back, like this:

 

protected function addSavedItem(obj:XML):void {
var stageItem:AddedItem = new AddedItem();
stageItem.source = "/ttest/images/full/"+obj.img;
stageItem.itemName = obj.itemName;
stageItem.name = obj.itemName;

trace(" adding saved stage item name = "+stageItem.name);

myManager.addItem(stageItem);
myManager.applyFullXML(roomXML,myManager);
updateItemCount();
}

 

Which gives me this:

20110207-pc7s249g98ffk287ttctkek7hu.jpg

 

As you can see, tracing each transform item's name gives me the correct name (in red here) and obviously the gray boxes are the correct size. But 2 of the 3 items are on the stage but not in the correct positions (i.e., the gray boxes).

Link to comment
Share on other sites

It's acting as though it's not able to find your object on the stage - remember, everything is based on their instance name(s) and they must be in the same DisplayObjectContainer (have the same parent). Is that the case here? (it wasn't clear based on what you posted). Also, it's generally considered a poor practice to have instance names that contain special characters like spaces.

 

I noticed you addItem() before you applyFullXML(), but don't do that - when you applyFullXML(), it will automatically add the items when it finds them based on their instance names.

 

If you're still having trouble, would you mind sending me a sample FLA that demonstrates the issue? You do NOT need to send your production files - just the simplest possible FLA that reproduces the issue.

Link to comment
Share on other sites

I have emailed you the Flex file. It's as stripped down as it can be, I doubt you can run it but maybe you can see what I've been trying.

 

It's acting as though it's not able to find your object on the stage - remember, everything is based on their instance name(s) and they must be in the same DisplayObjectContainer (have the same parent). Is that the case here? (it wasn't clear based on what you posted).

 

This is the first part I am missing... the TM is myManager, which is a child or a BorderContainer "workspace" which is a child of a VGroup "mainContainer". When I try to add my elements, where do I add them? The first time around, I am adding to the TM, but are you saying to prepare for reload I don't?

 

I noticed you addItem() before you applyFullXML(), but don't do that - when you applyFullXML(), it will automatically add the items when it finds them based on their instance names.

 

That's the second part that's confusing me... I guess I am having a hard time seeing how it "finds" them if they are no part of the TM.

Link to comment
Share on other sites

I have emailed you the Flex file. It's as stripped down as it can be, I doubt you can run it but maybe you can see what I've been trying.

You're right - it wouldn't publish/compile properly.

 

This is the first part I am missing... the TM is myManager, which is a child or a BorderContainer "workspace" which is a child of a VGroup "mainContainer". When I try to add my elements, where do I add them? The first time around, I am adding to the TM, but are you saying to prepare for reload I don't?

I think one key concept you might be missing is that a TransformManager is NOT a DisplayObjectContainer. When you add an item to a TransformManager, it simply tells TransformManager that it should make that targetObject transformable. So if sprite1 is a child of parent1 and then you myManager.addItem(sprite1), it doesn't reparent sprite1 at all - it still exists in parent1.

 

That's the second part that's confusing me... I guess I am having a hard time seeing how it "finds" them if they are no part of the TM.

In the example above, let's say you have parent1 that contains child1, child2, and child3 (all with instance names accordingly). Then you addItem() each of the child DisplayObjects to your myManager. Then you export the XML. You're fine so far. Now when you want to come back and re-apply the XML, you'd create your TransformManager ("myManager" in this case). Then you make sure that child1, child2, and child3 are named accordingly and are in parent1 like before. Then you applyFullXML() on myManager and it will look for child1, child2, and child3 and apply all the transformations as indicated in the XML.

 

Make sense?

Link to comment
Share on other sites

Thanks. I sent you a new file with some explanation. For the benefit of others, I reiterate a bit here.

 

When you add an item to a TransformManager, it simply tells TransformManager that it should make that targetObject transformable. So if sprite1 is a child of parent1 and then you myManager.addItem(sprite1), it doesn't reparent sprite1 at all - it still exists in parent1.

 

That's my confusion, How do I add this item to a DisplayObject and THEN to the TM? In my example, I have a BorderContainer (id='container') with a TM (id='myManager') inside of it. So, I create a new Image instance, set up its source etc. and I can then add it to "container". But a subsequent call to add it to the TM does not work (if I only add it to the TM, it works).

 

protected function addNewItem(img:String):void {
var newImage:Image = new Image();
newImage.source = "images/full/"+img;
newImage.x = 100;
newImage.y = 200;
       newImage.name = "bird";
container.addElement(newImage);
myManager.addItem(newImage);
}

 

 

The relationship between this parent object and the TM escapes me, sorry. Any example you can provide would be appreciated.

Link to comment
Share on other sites

My apologies - I completely missed the fact that you were using FlexTransformManager rather than TransformManager. In that case, yes, FlexTransformManager is a Canvas object, so it is indeed a DisplayObjectContainer. When you addItem() to a FlexTransformManager, it does reparent the object into the FlexTransformManager Canvas. It's totally appropriate for you to addItem() before you applyFullXML().

 

I didn't see anywhere in the example you sent me where you're trying to apply the XML or export it. That makes it tough to troubleshoot. From what I did see, though, I bet the problem is what I mentioned earlier - you never set the "name" property for your items. Keep in mind that the targetObject's name is the only way TransformManager can uniquely identify the instances when it's trying to link up the XML with the associated targetObjects. See what I mean? Like if you have objects with the names "child1", "child2" and "child3" when you exportFullXML(), then when you applyFullXML(), it will look for "child1", "child2", and "child3". For each one that it cannot find, it will create a gray box for you (for convenience) so that you can load the assets into those gray boxes.

 

Does that help?

Link to comment
Share on other sites

I will try that and report back. For the simplified case I emailed, I stripped out the save and reload to focus on the reparenting thing.

 

If you take a look at my original post, you can see how I was trying to do it. The saving the xml works, I get an XML file like I posted originally. I load that in, it loads correctly. So, I loop through my XMLList of all the objects in the project, add the ones that match the XML file to the TM, and applyFullXML. I thought I had it, except as you can see although there are TransformItems with names that match the XML, only one was moved to its gray box while the other 2 did not.

 

I will add in that part to my test project and send it along later. Thanks.

Link to comment
Share on other sites

Oh, I just noticed something else that might be helpful - it looks like you call addSavedItem() several times, once for each item. Notice that inside addSavedItem(), you also call applyFullXML(). So imagine the first time addSavedItem() gets called - only ONE of the items will be there, so when applyFullXML() is called at that point, the other 2 (or whatever) objects are missing! That's why one works and the others get the gray box. you should add all your items to the FlexTransformManager and THEN applyFullXML().

Link to comment
Share on other sites

Yes, that turned out to be the key item. That and the confusion over the FlexTransformManager being a DisplayObjectContainer.

 

It works like a charm now! Very impressive. This project has a lot of interesting feature requests, so I might need to pick your brain some more. Thanks for your help on this.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...