dandoen Posted October 11, 2012 Share Posted October 11, 2012 I'm looping through all the items of my XML and use LoaderMax to load my SWFs onto stage, and trigger a function to generate video items and text items. This looks like this: for each (var item in Main.XMLLiveItems.items.*) { if (item.@type == "static") { Main.queue.insert(new SWFLoader("media/"+item.@name, { name:item.@id, container:area, alpha: 0, onComplete: itemLoaded }),item.@level); } else if (item.@type == "text") { createTextAsset(item); } else if (item.@type == "video") { createVideoAsset(item); } } However, this messes up the levels since LoaderMax loads the queue after my textassets and videos have been loaded onto stage. I can't add the text assets or the video assets to my stage (called area) when specifying the index, because the number of children is still zero when the createTextAsset and createVideoAsset functions are called. I've tried to first use 'applyFullXML' and then add the textfields and videoloaders as a child to the placeholders. This turned out the way I wanted, except the textfields did not scale properly (using the scaleWidthAndHeight property) since they were now a child of a sprite. I am currently not sure what to do so was hoping for a push in the right direction. Thanks again. Link to comment Share on other sites More sharing options...
GreenSock Posted October 11, 2012 Share Posted October 11, 2012 I read your question several times and I'm still pretty foggy on exactly what the question/issue is. I will say that if you're trying to scale a TextField so that only the container resizes while the text itself doesn't scale, it is imperative that you NOT wrap it in another Sprite because changing the width/height of a Sprite always scales all of the contents/children whereas Flash's TextFields have special logic built in to allow only resizing the edges. See what I mean? If you still need help, maybe you could create a SUPER simple example that clearly demonstrates the problem. Please don't post your production files - just something very basic. That really helps us to identify the issue. Link to comment Share on other sites More sharing options...
dandoen Posted October 12, 2012 Author Share Posted October 12, 2012 Thanks, I understand that when the sprite container is being resized the contents (in this case the textfield) is being resized as well. But am not really sure what to do in order to work around this. This is the simplest example I can come up with: import com.greensock.*; import com.greensock.easing.*; import com.greensock.transform.TransformItem; import com.greensock.transform.TransformManager; import com.greensock.events.TransformEvent; import com.greensock.loading.*; import flash.display.Sprite; import flash.text.TextField; var XMLLive:XML = <transformManager> <settings allowDelete="1" allowMultiSelect="0" autoDeselect="1" constrainScale="0" lockScale="0" scaleFromCenter="0" lockRotation="0" lockPosition="0" arrowKeysMove="0" forceSelectionToFront="1" lineColor="3381759" handleColor="16777215" lineThickness="1" handleSize="8" paddingForRotation="12" hideCenterHandle="0"/> <items> <item id="1" type="static" forall="0" user_id="1" name="logo.swf" link="" url="" state="1" user="" level="1" a="1.0000000000000000" b="0.0000000000000000" c="0.0000000000000000" d="1.0000000000000000" tx="292" ty="322" xOffset="-7" yOffset="-8" rawWidth="417" rawHeight="108" scaleMode="scaleNormal" hasSelectableText="0" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity"><![CDATA[]]></item> <item id="2" type="text" forall="0" user_id="2" name="" link="" url="" state="1" user="" level="0" a="1.0000000000000000" b="0.0000000000000000" c="0.0000000000000000" d="1.0000000000000000" tx="0" ty="0" xOffset="0" yOffset="0" rawWidth="200" rawHeight="100" scaleMode="scaleWidthAndHeight" hasSelectableText="1" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity"><![CDATA[<P ALIGN="CENTER">Some text</P>]]></item> <item id="3" type="video" forall="0" user_id="2" name="UAOxCqSxRD0" link="" url="" state="1" user="" level="2" a="1.0000000000000000" b="0.0000000000000000" c="0.0000000000000000" d="1.0000000000000000" tx="0" ty="190" xOffset="0" yOffset="0" rawWidth="600" rawHeight="400" scaleMode="scaleNormal" hasSelectableText="0" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity"><![CDATA[]]></item> </items> </transformManager> var manager = new TransformManager(); var queue = new LoaderMax({name:"mainQueue"}); for each (var item in XMLLive.items.*) { if (item.@type == "static") { queue.append(new SWFLoader("media/"+item.@name, { name:item.@id, container:stage, onComplete: createStaticAsset })); } else if (item.@type == "text") { createTextAsset(item); } else if (item.@type == "video") { createVideoAsset(item); } } queue.load(); function assetData(mc) { var data = XMLLive.items.item.(@id==mc.name)[0]; return data; } function createStaticAsset(e) { var mc = stage.getChildByName(e.target.name); manager.applyItemXML(assetData(mc),stage,0xFF0000); } function createTextAsset(item) { var tf = new TextField(); tf.htmlText = item; tf.width = item.@rawWidth; tf.height = item.@rawHeight; var mc = manager.applyItemXML(item,stage,0xFF0000); mc.addChild(tf); } function createVideoAsset(item) { var player = new Sprite(); var mc = manager.applyItemXML(item,stage,0xFF0000); mc.addChild(player); } Link to comment Share on other sites More sharing options...
GreenSock Posted October 13, 2012 Share Posted October 13, 2012 Oh, okay - I think I see the problem. You just need to add your TextField to the stage and name it a unique name so that when you applyItemXML() the TransformManager can find it. The DIsplayObject's name is what uniquely identifies it. So here is the revised code (only a couple of minor edits were necessary): var XMLLive:XML = <transformManager> <settings allowDelete="1" allowMultiSelect="0" autoDeselect="1" constrainScale="0" lockScale="0" scaleFromCenter="0" lockRotation="0" lockPosition="0" arrowKeysMove="0" forceSelectionToFront="1" lineColor="3381759" handleColor="16777215" lineThickness="1" handleSize="8" paddingForRotation="12" hideCenterHandle="0"/> <items> <item id="1" type="static" forall="0" user_id="1" name="logo.swf" link="" url="" state="1" user="" level="1" a="1.0000000000000000" b="0.0000000000000000" c="0.0000000000000000" d="1.0000000000000000" tx="292" ty="322" xOffset="-7" yOffset="-8" rawWidth="417" rawHeight="108" scaleMode="scaleNormal" hasSelectableText="0" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity"><![CDATA[]]></item> <item id="2" type="text" forall="0" user_id="2" name="tf" link="" url="" state="1" user="" level="0" a="1.0000000000000000" b="0.0000000000000000" c="0.0000000000000000" d="1.0000000000000000" tx="0" ty="0" xOffset="0" yOffset="0" rawWidth="200" rawHeight="100" scaleMode="scaleWidthAndHeight" hasSelectableText="1" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity"><![CDATA[<P ALIGN="CENTER">Some text</P>]]></item> <item id="3" type="video" forall="0" user_id="2" name="UAOxCqSxRD0" link="" url="" state="1" user="" level="2" a="1.0000000000000000" b="0.0000000000000000" c="0.0000000000000000" d="1.0000000000000000" tx="0" ty="190" xOffset="0" yOffset="0" rawWidth="600" rawHeight="400" scaleMode="scaleNormal" hasSelectableText="0" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity"><![CDATA[]]></item> </items> </transformManager> var manager = new TransformManager(); var queue = new LoaderMax({name:"mainQueue"}); for each (var item in XMLLive.items.*) { if (item. @ type == "static") { queue.append(new SWFLoader("media/"+item.@name, { name:item.@id, container:stage, onComplete: createStaticAsset })); } else if (item.@type == "text") { createTextAsset(item); } else if (item.@type == "video") { createVideoAsset(item); } } queue.load(); function assetData(mc) { var data = XMLLive.items.item.(@id==mc.name)[0]; return data; } function createStaticAsset(e) { var mc = stage.getChildByName(e.target.name); manager.applyItemXML(assetData(mc),stage,0xFF0000); } function createTextAsset(item) { var tf = new TextField(); tf.htmlText = item; tf.width = item. @ rawWidth; tf.height = item. @ rawHeight; tf.name = item.@name; //Make sure the TextField is named appropriately so that the TransformManager can find it when you applyItemXML() stage.addChild(tf); var mc = manager.applyItemXML(item,stage,0xFF0000); } function createVideoAsset(item) { var player = new Sprite(); var mc = manager.applyItemXML(item,stage,0xFF0000); mc.addChild(player); } So I just named the TextField in the XML and I added a couple of lines to the createTextAsset() method. Does that clear things up? Link to comment Share on other sites More sharing options...
dandoen Posted October 13, 2012 Author Share Posted October 13, 2012 Thanks. The reason why I was taking the route of adding it to the placeholder sprite was because of another issue that is occurring now (which I vaguely explained in my initial post). Correct me if I'm wrong but this is what is currently happening: 1. Loop function goes through all assets and adds text and video assets to stage while adding "static" assets to the LoaderMax queue 2. The queue is loaded after the loop is done with adding the text/video assets to stage The issue here is that the levels as defined in the XML file won't match the "real" levels on stage. For example, a textfield has level 2 (out of 3 items, which means that it should be on top of everything else). applyItemXML is called for the textfield before the queue is loaded and so before the static item (with a lower level) is on stage. Which means applyItemXML sets the level to the highest childIndex, which is 0 at that time. This results in the video assets & text assets always be below the static assets due to the way it's been added to stage - ignoring the levels of the XML. Hope I managed to be a bit more clear this time, thanks again. Link to comment Share on other sites More sharing options...
dandoen Posted October 13, 2012 Author Share Posted October 13, 2012 The best solution seems to be doing applyItemXML to create a placeholder sprite along with adding it to the queue and using the placeholder sprite as the container for the LoaderMax item. Below's the code - just in case someone else finds it useful. Thanks Jack, could not have done it without you! import com.greensock.*; import com.greensock.easing.*; import com.greensock.transform.TransformItem; import com.greensock.transform.TransformManager; import com.greensock.events.TransformEvent; import com.greensock.loading.*; import flash.display.Sprite; import flash.text.TextField; var XMLLive:XML = <transformManager> <settings allowDelete="1" allowMultiSelect="0" autoDeselect="1" constrainScale="0" lockScale="0" scaleFromCenter="0" lockRotation="0" lockPosition="0" arrowKeysMove="0" forceSelectionToFront="1" lineColor="3381759" handleColor="16777215" lineThickness="1" handleSize="8" paddingForRotation="12" hideCenterHandle="0"/> <items> <item id="1" type="static" forall="0" user_id="1" name="logo.swf" link="" url="" state="1" user="" level="1" a="1.0000000000000000" b="0.0000000000000000" c="0.0000000000000000" d="1.0000000000000000" tx="2" ty="160" xOffset="-7" yOffset="-8" rawWidth="417" rawHeight="108" scaleMode="scaleNormal" hasSelectableText="0" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity"><![CDATA[]]></item> <item id="2" type="text" forall="0" user_id="2" name="tf2" link="" url="" state="1" user="" level="0" a="1.0000000000000000" b="0.0000000000000000" c="0.0000000000000000" d="1.0000000000000000" tx="120" ty="200" xOffset="0" yOffset="0" rawWidth="200" rawHeight="100" scaleMode="scaleWidthAndHeight" hasSelectableText="1" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity"><![CDATA[<P ALIGN="CENTER">Some text</P>]]></item> <item id="3" type="video" forall="0" user_id="2" name="UAOxCqSxRD0" link="" url="" state="1" user="" level="2" a="1.0000000000000000" b="0.0000000000000000" c="0.0000000000000000" d="1.0000000000000000" tx="0" ty="190" xOffset="0" yOffset="0" rawWidth="600" rawHeight="400" scaleMode="scaleNormal" hasSelectableText="0" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity"><![CDATA[]]></item> </items> </transformManager> var manager = new TransformManager(); var queue = new LoaderMax({name:"mainQueue"}); for each (var item in XMLLive.items.*) { if (item.@type == "static") { queue.append(new SWFLoader("media/"+item.@name, { name:item.@id, container: prepareStaticAsset(item), onComplete: createStaticAsset })); } else if (item.@type == "text") { createTextAsset(item); } else if (item.@type == "video") { createVideoAsset(item); } } queue.load(); function assetData(mc) { var data = XMLLive.items.item.(@id==mc.name)[0]; return data; } function prepareStaticAsset(item) { var mc = manager.applyItemXML(item,stage); return mc; } function createStaticAsset(e) { //var mc = stage.getChildByName(e.target.name); } function createTextAsset(item) { var tf = new TextField(); tf.name = item.@name; tf.htmlText = item; stage.addChild(tf); var mc = manager.applyItemXML(item,stage); } function createVideoAsset(item) { var player = new Sprite(); player.name = item.@name; stage.addChild(player); var mc = manager.applyItemXML(item,stage); } 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now