Jump to content
GreenSock

Search In
  • More options...
Find results that contain...
Find results in...
ilanb

applyItemXML don't work for me

Recommended Posts

Hi,

 

I try to export and import transform information for a textfield "myTxtBan" in a movieClip "mc"

I have a little class here:

 

I can export transform in xml, no problem work like a charm :-)

 

When I try to reimport nothing happen, textfield is always at same position, it's strange because if I use the property "tx" and "ty" directly to myTxtBan, it's work !

 

Any idea ?

 

Thx all

 

myTxtBan.x = main.instance.bannerData.listSlides.getSlideById(_id).tx;
myTxtBan.y = main.instance.bannerData.listSlides.getSlideById(_id).ty;

 

the xml (import and export):

 

<?xml version="1.0" encoding="utf-8"?>
<slides>
  <type idType="4" idSize="1"/>
  <slide id="0">
 <img1 posX="4.5" posY="4.5">files/imgs/OBESITE_2_250X250/etiquette.png</img1>
 <img2 posX="4.5" posY="4.5">files/imgs/OBESITE_2_250X250/chat.png</img2>
 <txt posX="35" posY="68.5"><![CDATA[<TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="Arial" SIZE="20" COLOR="#CCCCCC" LETTERSPACING="0" KERNING="0">Your animal<FONT COLOR="#333333"></FONT></FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="Arial" SIZE="20" COLOR="#FF0000" LETTERSPACING="0" KERNING="0">seems to be</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="Arial" SIZE="20" COLOR="#FF0000" LETTERSPACING="0" KERNING="0">overweight ?</FONT></P></TEXTFORMAT>]]></txt>
 <item name="myTxtBan" level="9" a="1" b="0" c="0" d="1" tx="37" ty="70.5" xOffset="-2" yOffset="-2" rawWidth="143" rawHeight="74" scaleMode="scaleWidthAndHeight" hasSelectableText="1" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity" lockScale="0" lockPosition="0" lockRotation="1" constrainScale="0" minWidth="1" maxWidth="Infinity" minHeight="1" maxHeight="Infinity"/>
  </slide>
  <slide id="1">
 <img1 posX="4.5" posY="4.5">files/imgs/OBESITE_2_250X250/etiquette.png</img1>
 <img2 posX="4.5" posY="4.5">files/imgs/OBESITE_2_250X250/chat-ombre.png</img2>
 <txt posX="72" posY="82.5"><![CDATA[<TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="Arial" SIZE="20" COLOR="#CCCCCC" LETTERSPACING="0" KERNING="0">Excess weight<FONT COLOR="#333333"></FONT></FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="Arial" SIZE="20" COLOR="#FF0000" LETTERSPACING="0" KERNING="0">is not inevitable</FONT></P></TEXTFORMAT>]]></txt>
 <item name="myTxtBan" level="9" a="1" b="0" c="0" d="1" tx="74" ty="84.5" xOffset="-2" yOffset="-2" rawWidth="142" rawHeight="50" scaleMode="scaleWidthAndHeight" hasSelectableText="1" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity" lockScale="0" lockPosition="0" lockRotation="1" constrainScale="0" minWidth="1" maxWidth="Infinity" minHeight="1" maxHeight="Infinity"/>
  </slide>
  <slide id="2">
 <img1 posX="4.5" posY="4.5">files/imgs/OBESITE_2_250X250/etiquette.png</img1>
 <img2 posX="4.5" posY="4.5">files/imgs/OBESITE_2_250X250/chat-logoRC.png</img2>
 <txt posX="72.8" posY="78.5"><![CDATA[<TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="Arial" SIZE="20" COLOR="#EEEEEE" LETTERSPACING="0" KERNING="0">MAINTAIN THEIR</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="Arial" SIZE="20" COLOR="#EEEEEE" LETTERSPACING="0" KERNING="0">GOOD WEIGHT<FONT COLOR="#333333"></FONT></FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="Arial" SIZE="20" COLOR="#CCCCCC" LETTERSPACING="0" KERNING="0">ENSURE THEIR</FONT></P></TEXTFORMAT><TEXTFORMAT LEADING="2"><P ALIGN="CENTER"><FONT FACE="Arial" SIZE="20" COLOR="#CCCCCC" LETTERSPACING="0" KERNING="0">GOOD HEALTH</FONT></P></TEXTFORMAT>]]></txt>
 <item name="myTxtBan" level="9" a="1" b="0" c="0" d="1" tx="74.8" ty="80.5" xOffset="-2" yOffset="-2" rawWidth="177" rawHeight="98" scaleMode="scaleWidthAndHeight" hasSelectableText="1" minScaleX="-Infinity" maxScaleX="Infinity" minScaleY="-Infinity" maxScaleY="Infinity" lockScale="0" lockPosition="0" lockRotation="1" constrainScale="0" minWidth="1" maxWidth="Infinity" minHeight="1" maxHeight="Infinity"/>
  </slide>
</slides>

 

my class:

 

package tools
{
import com.greensock.events.TransformEvent;
import com.greensock.transform.*;

import data.DevData;

import flash.display.MovieClip;
import flash.geom.*;
import flash.text.TextFieldAutoSize;

import tools.CustomEvent;
import tools.Dispatcher;

public class TrsfManager
{
 private var _manager:TransformManager;
 private var mc:MovieClip;
 private var boundsRec:Rectangle;
 private var ti:TransformItem;
 private var _id:int;

 public var dataTrsfmanagerXmlExport:XML;
 public var dataTrsfmanagerXmlImport:XML;
 //-----------------------------------------------------------------------------------
 //
 // CONSTRUCTOR
 //
 //-----------------------------------------------------------------------------------

 public function TrsfManager()
 {
  //...
 }

 //-----------------------------------------------------------------------------------
 //
 // INIT
 //
 //-----------------------------------------------------------------------------------

 public function init(_mc:MovieClip, id:int):void
 {
  mc = _mc;
  _id = id;
  Dispatcher.addEventListener(DevData.TXT_CHANGE, reziseManager);

  _manager = new TransformManager({targetObjects:[]});
  _manager.addEventListener(TransformEvent.CLICK_OFF, deselectAllItem);
  _manager.lockRotation = true;
  _manager.arrowKeysMove = true;
  _manager.forceSelectionToFront = true;
  _manager.autoDeselect = false;

  // On adapte le bounds en fonction de la bannière
  switch(main.instance.bannerData.listSlides.getSlideTypeAndSize().idSize)
  {
   case 1:{setManager(0, 10, 250, 250);break;}
   case 2:{setManager(0, 10, 300, 250);break;}
   case 3:{setManager(150, 10, 400, 80);break;}
   default:{break;}
  } 
  mc.myTxtBan.autoSize = TextFieldAutoSize.LEFT;

 }

 private function setManager(xPos:int, yPos:int, recWidth:int, recHeight):void
 {
  boundsRec = new Rectangle(xPos, yPos, recWidth, recHeight);
  _manager.bounds = boundsRec;
  ti = _manager.addItem( mc.myTxtBan );
  ti.manualBoundsOffset = new Rectangle(0, 0, 0, 0);
  _manager.selectItem(mc.myTxtBan, false);

  // On applique les transformations au champ txt
  appliXmlTrsfManager();
 }

 private function deselectAllItem(evt:TransformEvent):void
 { 
  _manager.updateSelection(true);
 }

 private function reziseManager(event:CustomEvent):void
 {
  var sizeW:int = event.params._width;
  var sizeH:int = event.params._height;
  mc.myTxtBan.autoSize = TextFieldAutoSize.LEFT;
  _manager.updateSelection(true);
 }

 public function exportXmlTrsfManager():XML
 {
  dataTrsfmanagerXmlExport = _manager.exportItemXML(mc.myTxtBan);
  return dataTrsfmanagerXmlExport;
 }

 private function appliXmlTrsfManager():void
 {
  var thisItemXML:XML = new XML(main.instance.bannerData.listSlides.getSlideById(_id).item);
  _manager.applyItemXML(thisItemXML);
 }
}
}

Link to comment
Share on other sites

A few questions:

 

1) Did you make sure that your mc.myTxtBan object was named exactly "myTxtBan"? Like if you trace(mc.myTxtBan.name), does it say "myTxtBan"? That's the only way TransformManager could associate the data with the actual object/instance (its name) because XML is only text.

 

2) Have you tried adding [0] after item? I believe the way you wrote it would actually return a XMLList whereas you'd want a String to feed into your new XML object. And maybe even use toXMLString(). Like:

new XML(main.instance.bannerData.listSlides.getSlideById(_id).item[0].toXMLString());

Link to comment
Share on other sites

Hi,

 

thx for reply,

Did you make sure that your mc.myTxtBan object was named exactly "myTxtBan"? Like if you trace(mc.myTxtBan.name), does it say "myTxtBan"? That's the only way TransformManager could associate the data with the actual object/instance (its name) because XML is only text.

 

Yes sure ! :-) that name in the fla

 

Have you tried adding [0] after item? I believe the way you wrote it would actually return a XMLList whereas you'd want a String to feed into your new XML object. And maybe even use toXMLString(). Like:

 

Yes but I have this error:

 

 

ReferenceError: Error #1069: La propriété 0 est introuvable sur Number et il n'existe pas de valeur par défaut.

at tools::TrsfManager/appliXmlTrsfManager()

 

here is my class where I get data:

 

package data
{  
public class ListSlideGame
{  
 private var _slide:Array;
 private var _slides:Array;
 private var _images:Array;
 private var _image:Array;

 private var galleryXml:XMLList;
 private var slideXml:XMLList;
 private var slideXmlType:XMLList;

 //--------------------------------------------------------------------------------------------------------------
 //
 // INIT
 //
 //--------------------------------------------------------------------------------------------------------------

 public function init(xml:XML):void
 {
  _slide = new Array();
  _slides = new Array();
  _images = new Array();
  _image = new Array();
  slideXmlType = new XMLList(xml.type);
  _slides.push( new Slides (slideXmlType.@idType, slideXmlType.@idSize) );

  for (var i:int = 0; i < xml.slide.length(); i++)
  {
slideXml = new XMLList(xml.slide[i]);
_slide.push
(
 new SlidesGame
 (
  slideXml.@id,
  slideXml.img1,
  slideXml.img1.@crossPosX,
  slideXml.img1.@crossPosY,
  slideXml.img1.@posX,
  slideXml.img1.@posY,
  slideXml.img2,
  slideXml.img2.@posX,
  slideXml.img2.@posY,
  slideXml.img3,
  slideXml.img3.@posX,
  slideXml.img3.@posY,
  slideXml.txt1,
  slideXml.txt2,
  slideXml.item,
  slideXml.item.@name,
  slideXml.item.@level,
  slideXml.item.@a,
  slideXml.item.@b,
  slideXml.item.@c,
  slideXml.item.@d,
  slideXml.item.@tx,
  slideXml.item.@ty,
  slideXml.item.@xOffset,
  slideXml.item.@yOffset,
  slideXml.item.@rawWidth,
  slideXml.item.@rawHeight,
  slideXml.item.@scaleMode,
  slideXml.item.@hasSelectableText,
  slideXml.item.@minScaleX,
  slideXml.item.@maxScaleX,
  slideXml.item.@minScaleY,
  slideXml.item.@maxScaleY,
  slideXml.item.@lockScale,
  slideXml.item.@lockPosition,
  slideXml.item.@lockRotation,
  slideXml.item.@constrainScale,
  slideXml.item.@minWidth,
  slideXml.item.@maxWidth,
  slideXml.item.@minHeight,
  slideXml.item.@maxHeight
 )
);
  }

  for (var j:int = 0; j < xml.gallery.image.length(); j++)
  {
galleryXml = new XMLList(xml.gallery.image[j]);
_image.push
 (
  new ImageGame
  (
   galleryXml.@id,
   galleryXml.@full,
   galleryXml.@thumb
  )
 );
  }

 }
 //--------------------------------------------------------------------------------------------------------------
 //
 // GETTERS
 //
 //--------------------------------------------------------------------------------------------------------------

 public function getGalleryLenght():Number
 {
  var numbImgs:Number = _image.length;
  return numbImgs;
 }

 public function getGalleryXmlList():XMLList
 {
  var xmlImgs:XMLList = galleryXml;
  return xmlImgs;
 }

 public function getSlideTypeAndSize():Slides
 {
  var slides:Slides;
  slides = _slides[0] as Slides;
  return slides;
 }

 public function getSlideLenght():Number
 {
  var numbImgsSlide:Number = _slide.length;
  return numbImgsSlide;
 }

 public function getSlideById(idS:int):SlidesGame
 {
  var slide:SlidesGame;
  var index:int = 0;
  var find:Boolean = false;

  while (index < _slide.length && !find)
  {
slide = _slide[index] as SlidesGame;
if (slide.id == idS)
 find = true;
else
 index++;
  }

  if (!find)
return null;
  else
return slide;
 }

 public function getImgGalleryById(idS:int):ImageGame
 {
  var imgG:ImageGame;
  var index:int = 0;
  var find:Boolean = false;

  while (index < _image.length && !find)
  {
imgG = _image[index] as ImageGame;
if (imgG.id == idS)
 find = true;
else
 index++;
  }

  if (!find)
return null;
  else
return imgG;
 }
}
}

 

package data
{
import data.DevData;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import tools.CustomEvent;
import tools.Dispatcher;

public class BannerData
{
 private var xmlLoader:URLLoader;
 private var loader:URLLoader;
 private var _listSlides:ListSlideGame;
 private var urlImg:String;

 //-----------------------------------------------------------------------------------
 //
 // INIT
 //
 //-----------------------------------------------------------------------------------

 public function init():void
 {
  urlImg = main.instance.getVarSlides_xml as String;
  _listSlides = new ListSlideGame();
  loadNewXml();
 }

 //-----------------------------------------------------------------------------------
 //
 // XML
 //
 //-----------------------------------------------------------------------------------

 private function loadNewXml():void
 {
  // Change les urls si online ou offline
  if(DevData.ONLINE == false)
  {
xmlLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, onNewXmlLoaded);
xmlLoader.load(new URLRequest(DevData.XML_PATH + main.instance.gameData.getConfigFromXmlById("slides_xml")));
  }
  else
  {
xmlLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, onNewXmlLoaded);
xmlLoader.load(new URLRequest(urlImg));
  }
 }

 private function onNewXmlLoaded(event:Event):void
 {
  xmlLoader.removeEventListener(Event.COMPLETE, onNewXmlLoaded);  

  _listSlides.init(new XML(event.target.data));
  onAllXmlLoaded();
 }

 //--------------------------------------------------------------------------------------------------------------
 //
 // ON ALL XML LOADED
 //
 //--------------------------------------------------------------------------------------------------------------

 private function onAllXmlLoaded():void{Dispatcher.dispatchEvent(new CustomEvent(DevData.GAME_BANNER_READY));}
 //--------------------------------------------------------------------------------------------------------------
 //
 // GETTERS
 //
 //--------------------------------------------------------------------------------------------------------------

 public function get listSlides():ListSlideGame{return _listSlides;}
}
}

 

package data
{  
import data.DevData;

public class SlidesGame
{   
 private var _id:int;
 private var _img1:String;
 private var _img2:String;
 private var _img3:String;
 private var _txt1:String;
 private var _txt2:String;
 private var _posXimg1:int;
 private var _posYimg1:int;
 private var _posXimg2:int;
 private var _posYimg2:int;
 private var _posXimg3:int;
 private var _posYimg3:int;
 private var _crossPosXimg1:int;
 private var _crossPosYimg1:int;
 private var _item:*;
 private var _name:*;
 private var _level:*;
 private var _a:*;
 private var _b:*;
 private var _c:*;
 private var _d:*;
 private var _tx:*;
 private var _ty:*;
 private var _xOffset:*;
 private var _yOffset:*;
 private var _rawWidth:*;
 private var _rawHeight:*;
 private var _scaleMode:*;
 private var _hasSelectableText:*;
 private var _minScaleX:*;
 private var _maxScaleX:*;
 private var _minScaleY:*;
 private var _maxScaleY:*;
 private var _lockScale:*;
 private var _lockPosition:*;
 private var _lockRotation:*;
 private var _constrainScale:*;
 private var _minWidth:*;
 private var _maxWidth:*;
 private var _minHeight:*;
 private var _maxHeight:*;

 //--------------------------------------------------------------------------------------------------------------
 //
 // INIT
 //
 //--------------------------------------------------------------------------------------------------------------

 public function SlidesGame
 (
  id:int,
  img1:String,
  crossPosXimg1:int,
  crossPosYimg1:int,
  posXimg1:int,
  posYimg1:int,
  img2:String,
  posXimg2:int,
  posYimg2:int,
  img3:String,
  posXimg3:int,
  posYimg3:int,
  txt1:String,
  txt2:String,
  item:*,
  name:*,
  level:*,
  a:*,
  b:*,
  c:*,
  d:*,
  tx:*,
  ty:*,
  xOffset:*,
  yOffset:*,
  rawWidth:*,
  rawHeight:*,
  scaleMode:*,
  hasSelectableText:*,
  minScaleX:*,
  maxScaleX:*,
  minScaleY:*,
  maxScaleY:*,
  lockScale:*,
  lockPosition:*,
  lockRotation:*,
  constrainScale:*,
  minWidth:*,
  maxWidth:*,
  minHeight:*,
  maxHeight:*
 )
 {
  _id = id;
  _img1 = img1;
  _crossPosXimg1 = crossPosXimg1;
  _crossPosYimg1 = crossPosYimg1;
  _posXimg1 = posXimg1;
  _posYimg1 = posYimg1;
  _img2 = img2;
  _posXimg2 = posXimg2;
  _posYimg2 = posYimg2;
  _img3 = img3;
  _posXimg3 = posXimg3;
  _posYimg3 = posYimg3;
  _txt1 = txt1;
  _txt2 = txt2;
  _item = item;
  _name = name;
  _level = level;
  _a = a;
  _b = b;
  _c = c;
  _d = d;
  _tx = tx;
  _ty = ty;
  _xOffset = xOffset;
  _yOffset = yOffset;
  _rawWidth = rawWidth;
  _rawHeight = rawHeight;
  _scaleMode = scaleMode;
  _hasSelectableText = hasSelectableText;
  _minScaleX = minScaleX;
  _maxScaleX = maxScaleX;
  _minScaleY = minScaleY;
  _maxScaleY = maxScaleY;
  _lockScale = lockScale;
  _lockPosition = lockPosition;
  _lockRotation = lockRotation;
  _constrainScale = constrainScale;
  _minWidth = minWidth;
  _maxWidth = maxWidth;
  _minHeight = minHeight;
  _maxHeight = maxHeight
 }
 //--------------------------------------------------------------------------------------------------------------
 //
 // GETs
 //
 //--------------------------------------------------------------------------------------------------------------

 public function get id():int
 {
  return _id;
 }

 public function get img1():String
 {  
  return _img1;
 }

 public function get img2():String
 {  
  return _img2;
 }

 public function get img3():String
 {  
  return _img3;
 }

 public function get txt1():String
 {  
  return _txt1;
 }

 public function get txt2():String
 {  
  return _txt2;
 }

 public function get posXimg1():int
 {
  return _posXimg1;
 }

 public function get posYimg1():int
 {
  return _posYimg1;
 }

 public function get posXimg2():int
 {
  return _posXimg2;
 }

 public function get posYimg2():int
 {
  return _posYimg2;
 }

 public function get posXimg3():int
 {
  return _posXimg3;
 }

 public function get posYimg3():int
 {
  return _posYimg3;
 }

 public function get crossPosXimg1():int
 {
  return _crossPosXimg1;
 }

 public function get crossPosYimg1():int
 {
  return _crossPosYimg1;
 }


 public function get item():int
 {
  return _item;
 }

 public function get name():int
 {
  return _name;
 }

 public function get level():int
 {
  return _level;
 }

 public function get a():int
 {
  return _a;
 }

 public function get b():int
 {
  return _b;
 }

 public function get c():int
 {
  return _c;
 }

 public function get d():int
 {
  return _d;
 }

 public function get tx():int
 {
  return _tx;
 }

 public function get ty():int
 {
  return _ty;
 }

 public function get xOffset():int
 {
  return _xOffset;
 }

 public function get yOffset():int
 {
  return _yOffset;
 }

 public function get rawWidth():int
 {
  return _rawWidth;
 }

 public function get rawHeight():int
 {
  return _rawHeight;
 }

 public function get scaleMode():int
 {
  return _scaleMode;
 }

 public function get hasSelectableText():int
 {
  return _hasSelectableText;
 }

 public function get minScaleX():int
 {
  return _minScaleX;
 }

 public function get maxScaleX():int
 {
  return _maxScaleX;
 }

 public function get minScaleY():int
 {
  return _minScaleY;
 }

 public function get maxScaleY():int
 {
  return _maxScaleY;
 }

 public function get lockScale():int
 {
  return _lockScale;
 }

 public function get lockPosition():int
 {
  return _lockPosition;
 }

 public function get lockRotation():int
 {
  return _lockRotation;
 }

 public function get constrainScale():int
 {
  return _constrainScale;
 }

 public function get minWidth():int
 {
  return _minWidth;
 }

 public function get maxWidth():int
 {
  return _maxWidth;
 }

 public function get minHeight():int
 {
  return _minHeight;
 }

 public function get maxHeight():int
 {
  return _maxHeight;
 }
}

 

Thanks

Link to comment
Share on other sites

It sounds like you're not passing in the XML correctly. Have you verified that you're only passing in a single node? Have you trace()'d the exact value you're passing in to ensure it is what you're expecting?

 

Also, have you tried defining the second parameter of applyItemXML()?

http://greensock.com/as/docs/transform/com/greensock/transform/TransformManager.html#applyItemXML()

 

If you're still having trouble, please zip up your project and send it to me via PM or e-mail so that I can publish and see exactly what's going on. If you can create a stripped-down version with only the essential code to reproduce the error, that would be best. The simpler the better.

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.
×