Jump to content
GreenSock

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

Add/Remove Items from the array.(SOLVED)

Recommended Posts

Can this be used in some way:

- addItems(targetObjects:Array, vars:Object):Array

to place this sprite

 

var rect:Sprite=new Sprite();

 

rect.graphics.lineStyle(1,0x000000);

rect.graphics.beginFill(0x0000FF,1);

//rect.graphics.drawRect(mouseX,mouseY,100,100);

 

rect.graphics.drawRect(0,10,100,100);

rect.graphics.endFill();

addChild(rect);

or movieclip

var squareshape:MovieClip=new Squareshape();

addChild(squareshape);

squareshape.x=-100;

squareshape.y=-100;

 

here

var manager:TransformManager = new TransformManager({targetObjects:[square1, square2,text}]

 

The idea is to add and remove items from the array of items to be controlled by the TransformManager

Link to comment
Share on other sites

Sure. I assume you're talking about the upcoming AS3 version of TransformManager, right? You can dynamically create Sprites and/or MovieClips and add them anytime. Either like this:

 

var manager:TransformManager = new TransformManager({targetObjects:[square1, square2,text]});

 

or like this:

 

var myTargets:Array = [];
//create Sprite here and draw a rectangle with the drawing API, then...
myTargets.push(myNewSprite);
myTargets.push(myNewMovieClip);
var manager:TransformManager = new TransformManager({targetObjects:myTargets});

 

or like this:

var manager:TransformManager = new TransformManager();
manager.addItem(myCustomSprite);
manager.addItem(myCustomMovieClip);

 

or even

 

var manager:TransformManager = new TransformManager();
manager.addItems([myCustomSprite, myCustomMovieClip]);

 

Lots of options to choose from :-) And you can remove them anytime with the removeItem() function too.

 

Does that answer your question?

Link to comment
Share on other sites

mostly, I tried your examples and they work great

 

here is what I Ultimately have in mind:

 

import gs.transform.*;

 

//var inc:uint = 0;

var ball:MovieClip = new Ball();

 

button.addEventListener(MouseEvent.CLICK,poof);

 

var myTargets:Array = [];

//create Sprite here and draw a rectangle with the drawing API, then...

function poof(evt:MouseEvent):void

{

 

var ball:MovieClip = new Ball();

//ball.x = 100 + inc * 10;

//ball.y = 300 - inc * 10;

ball.x = 300 ;

ball.y = 300 ;

addChild(ball)

//addChildAt(ball, 0);

//inc++;

 

myTargets.push(ball);

myTargets.push(ball);

//var manager:TransformManager = new TransformManager({targetObjects:myTargets});

}

 

//myTargets.push(ball);

//myTargets.push(ball);

 

 

var manager:TransformManager = new TransformManager({targetObjects:myTargets});

 

I want to use an event handler to draw either an api or place a sprite(the same way a user would draw many circles or squares) in the array and, hopefully TransformManager would be able to work with them.

Link to comment
Share on other sites

I'm not quite clear on what the problem is.

 

The Array you pass in to the constructor is just for the initial setup - TransformManager doesn't keep track of that Array and see if/when you add anything to it. Think of it as a convenient way to get around having to do a bunch of addItem() calls if you've already got a bunch of items on the stage that you want it to manage. Of course you could use addItems() too which is another convenience.

 

If you're going to add items to the TransformManager after it's instantiated, you need to use the addItem() or addItems() methods. Is that a problem?

Link to comment
Share on other sites

I just wasn't sure about the syntax, that's all , not so much a problem with the class itself.

 

I figured it out.

 

var myTargets:Array = [];

ball1.addEventListener(MouseEvent.CLICK,poof);

function poof(evt:MouseEvent):void

{

var ball2:MovieClip = new Ball();

ball2.x = 50 ;

ball2.y = 50;

addChild(ball2);

manager.addItem(ball2);

//array variable name.addItem(object);

}

 

var manager:TransformManager = new TransformManager({targetObjects:myTargets});

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