0 Replies Latest reply on Oct 23, 2006 1:50 PM by Garyl Woolworth

    External targets for addChild in states

    Garyl Woolworth Level 1
      Right now I'm working on a project that currently is creating dynamic states from a function and one of the arguments that is being passed to this state needs to be the filename of the child I want to add to the state. The following is the function I have so far.

      private function addStates(wContent:String, wX:Number, wY:Number, wWidth:Number, wHeight:Number):void {
      var state:State;
      var addChild:AddChild;
      var setXProperty:SetProperty;
      var setYProperty:SetProperty;
      var setZProperty:SetProperty;
      var setHeightProperty:SetProperty;
      var setWidthProperty:SetProperty;


      state = new State();
      state.name ="state"+positionIndex.toString();

      // position every window within that state
      setXProperty = new SetProperty();
      setXProperty.target = windowArray[positionIndex];
      setXProperty.name = "x";

      setYProperty = new SetProperty();
      setYProperty.target = windowArray[positionIndex];
      setYProperty.name = "y";

      setHeightProperty = new SetProperty();
      setHeightProperty.target = windowArray[positionIndex];
      setHeightProperty.name = "height";

      setWidthProperty = new SetProperty();
      setWidthProperty.target = windowArray[positionIndex];
      setWidthProperty.name = "width";

      // set property values based off arguments
      setXProperty.value = wX;
      setYProperty.value = wY;
      setHeightProperty.value = wHeight;
      setWidthProperty.value = wWidth;
      positionIndex++;

      // add children to state
      addChild.relativeTo = mainCanvas;
      addChild.target = wContent;

      // push all of the overrides into the state array
      state.overrides.push (setXProperty);
      state.overrides.push(setYProperty);
      state.overrides.push(setHeightProperty);
      state.overrides.push(setWidthProperty);
      state.overrides.push(addChild);

      // push the state onto the states array
      states.push(state);
      addTransitions(state.name);
      }

      Now as you can see wContent is currently a string however that's where it is giving me the error of "1067: Implicit coercion of a value of type String to an unrelated type flash.display:DisplayObject." because you can't add a string as a child but I do not know of the correct way to syntax this. The child I want to add will be testChild.mxml which is a canvas with 4 buttons inside of. The child will always be a canvas just the buttons and the actions those buttons do will be different. So basically I need to pass " testChild.mxml" as a string or whatever through the addStates() method as wContent and then make a child to the state with that. Anyone got any ideas?