Jump to content
Search Community

Help with Sprites please

groovdafied test
Moderator Tag

Recommended Posts

So I have a FOR loop running in a xml function. The loop creates a sprite, gives it a name it, assigns a listener to the sprite when a mouse_down event occurs (called mDown), push the sprite name to an array and it appears on the stage perfectly.

 

Now the mDown function is created, it works until I write the TweenMax code to animate the sprite names listed in the array, but I get a nasty 1069 error. I'm guessing that TweenMax can't find the name of the sprite from the listed array. I even tried to use TweenMax with just the name of the sprite and flash reports back that it's an undefined property.

 

So my question is how can I use TweenMax in a different function to animate the sprites I created? I'm sorry if I'm not explaining this clearly, I'm still trying to learn ActionScript syntax and conventions. I'm pasting the code below if someone could please help? Thank you!

 

 

import flash.display.Sprite;
import com.greensock.*;
import com.greensock.easing.*;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.events.MouseEvent;
import flash.text.TextFormat;

//load XML file

var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("MyXML.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
var categoryArray:Array = new Array();

function processXML(e:Event):void
{
myXML = new XML(e.target.data);
var catCount = myXML.BTN.length();
var btnXpos:Number = myXML.BTN.xPos;

for (var i:int = 1; i	{
	var catName = myXML.BTN[i].toString()

	var b:MovieClip = new squareBTN();
	var myFont = new Font1();

	var myFormat:TextFormat = new TextFormat();
	myFormat.size = 30;
	myFormat.align = TextFormatAlign.CENTER;
	myFormat.font = myFont.fontName;

	var txt:TextField=new TextField();
	txt.defaultTextFormat = myFormat;
	txt.embedFonts = true;
	txt.selectable = false;
	txt.text = catName;
	txt.width = 150;
	txt.y = -25;
	b.x = btnXpos;
	b.y = stage.stageHeight / 2;

	b.name = catName;
	trace("b.name="+b.name);
	b.scaleX = .5;
	b.scaleY = .5;


	categoryArray.push(catName);

	addChild(;
	b.addChild(txt);
	b.alpha = 0;
	btnXpos = btnXpos + 200;
	b.addEventListener(MouseEvent.MOUSE_DOWN, mDown);
	trace(categoryArray);
	b.tween = TweenMax.to(b, 1, {alpha:100, scaleY:1, scaleX:1});




}

}



function mDown(e:MouseEvent):void
{
var container:Sprite = Sprite(e.currentTarget);
var btnName = container.name;
TweenMax.allTo(categoryArray, 1, {alpha:0});
trace("Array="+categoryArray);


}

Link to comment
Share on other sites

hello groovdafied,

 

from what I can muster I'd start here:

 

categoryArray.push(catName);

 

this code is pushing a string into your categoryArray.

 

allTo() needs an array of display objects, not String values of their .name property. i know, its weird. its more an AS3 thing and not a tweenMax issue.

 

try this instead

 

categoryArray.push(B);

 

this will actually be adding each b (or a reference to each B) to the array.

Link to comment
Share on other sites

hello groovdafied,

 

from what I can muster I'd start here:

 

categoryArray.push(catName);

 

this code is pushing a string into your categoryArray.

 

allTo() needs an array of display objects, not String values of their .name property. i know, its weird. its more an AS3 thing and not a tweenMax issue.

 

try this instead

 

categoryArray.push(B);

 

this will actually be adding each b (or a reference to each B) to the array.

 

EH MEH GAWD!!! It makes total sense and it actually worked! *tears*

 

Thank you so much for your help! I also had to remove the b.name = xmlNewname in order for this to work.

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