Jump to content
Search Community

Need help tweening items in an if else condition

obi_wan test
Moderator Tag

Recommended Posts

I have a bunch of items that I loop through, when the user selects the item, it does a couple of things.

 

1. Plays a sound

2. Animates the selected item (scales and adds glow)

3. Scales any other other item not equal to selected item or

 

That works ok but I wanted to bullet proof this by adding another condition which basically checks that if the selected item is clicked and the sound has not loaded don't do anything. Currently when you select an item it scales up and plays the sound and if you select another item while the sound is playing it scales down every item until you select a new item when it is done loading.

 

If anyone can please take a look at the code I have attached and give me some pointers that would be greatly appreciated.

 

private function easelItemHandler(event:MouseEvent):void
{
var totalEaselItems	:Number = _xmlsource.easelAssets.alphabet.length();
var selectedItem	:String = event.currentTarget.name;

for (var i:int = 0; i	{
	if (selectedItem == _levelTwoArray[i] && _soundManager.gameSound.playProgress == 1)
		{
			_soundManager.playAudio(_soundManager.alphabetAudioArray[i],_soundManager.mp3Loader);
			TweenLite.to(event.currentTarget, .25, {transformAroundCenter:{scaleX:1, scaleY:1}});
			TweenMax.to(event.currentTarget,.25, {glowFilter:{color:0xffffff, alpha:1, blurX:80, blurY:80, strength:0.8, quality:1}});
			_easel.displayDrawer.titleContainer.name_txt.text = _xmlsource.drawerAssets.drawerItem.@title[i];
			TweenLite.to(_easel.displayDrawer.imageContainer.getChildByName("drawerItemClip"+i), .5, {alpha:1});
		if(_levelItemsArray.length != 0)
			{
				_arrayManager.removeItemFromArray(_levelItemsArray,selectedItem);
			}
		}

	if(selectedItem == _levelTwoArray[i] && _soundManager.gameSound.playProgress != 1)
		{
			trace("selected item dont scale down or fade out");
		}				
		else 
		{
			TweenLite.to(_easel.alphabetContainer.getChildByName("easelItemClip"+ i), .25, {transformAroundCenter:{scaleX:.6, scaleY:.6}});
			TweenMax.to(_easel.alphabetContainer.getChildByName("easelItemClip"+ i),.25, {glowFilter:{remove:true}});
			TweenLite.to(_easel.displayDrawer.imageContainer.getChildByName("drawerItemClip"+i), .5, {alpha:0});
		}
}
}

Link to comment
Share on other sites

that if the selected item is clicked and the sound has not loaded don't do anything

 

it seems you need a way to know if the item is clicked or not. you could give each item an isSelected property. then every time you click an item set

 

thisItem.isSelected = true

 

or something like that. of course you would also have to set that to false when you click another item.

 

or you could remove the MouseEvent.CLICK eventListener from the item as soon as it is clicked thus preventing it from being clicked again.

Link to comment
Share on other sites

I am stumped, I think I got myself in a little pickle here LOL. This is how I am setting up the individual items:

 

	private function initEaselItems():void
	{
		var easelItemURL			:String;
		var totalEaselItems			:Number = _xmlsource.easelAssets.alphabet.length();
		for(var i:int=0; i			{
			easelItemURL 			= _xmlsource.easelAssets.alphabet.@imageURL[i];
			_easelItemClip			= new MovieClip();
			_easelItemClip.name		= "easelItemClip"+[i];
			_easelItemClip.index	= [i];
			_easelItemClip.x		= _xmlsource.easelAssets.alphabet.@xPos[i];
			_easelItemClip.y		= _xmlsource.easelAssets.alphabet.@yPos[i];
			_easelItemClip.alpha	= 0;
			_easelItem 				= new ImageLoader(easelItemURL,{estimatedBytes:2400,container:_easelItemClip});
			_easel.alphabetContainer.addChild(_easelItemClip);
			_easelItem.load();
			_easelItemClip.buttonMode 		= true;
			_easelItemClip.addEventListener(MouseEvent.CLICK,easelItemHandler,false,0,true);
			TweenLite.to(_easelItemClip, .5, {alpha:1, scaleX:.6, scaleY:.6, delay:(i*.03)});
			_levelTwoArray.push(_easelItemClip.name);
			_levelItemsArray.push(_easelItemClip.name);
		}
		initDrawerContent();
	}

 

 

And this is where I am just confused and lost in the condition and loop:

	private function easelItemHandler(event:MouseEvent):void
	{
		var totalEaselItems	:Number = _xmlsource.easelAssets.alphabet.length();
		var selectedItem	:String = event.currentTarget.name;

		for (var i:int = 0; i			{
			if (selectedItem == _levelTwoArray[i] && _soundManager.gameSound.playProgress == 1)
			{
				_soundManager.playAudio(_soundManager.alphabetAudioArray[i],_soundManager.mp3Loader);
				TweenLite.to(event.currentTarget, .25, {transformAroundCenter:{scaleX:1, scaleY:1}});
				TweenMax.to(event.currentTarget,.25, {glowFilter:{color:0xffffff, alpha:1, blurX:80, blurY:80, strength:0.8, quality:1}});
				_easel.displayDrawer.titleContainer.name_txt.text = _xmlsource.drawerAssets.drawerItem.@title[i];
				TweenLite.to(_easel.displayDrawer.imageContainer.getChildByName("drawerItemClip"+i), .5, {alpha:1});
				if(_levelItemsArray.length != 0)
				{
					_arrayManager.removeItemFromArray(_levelItemsArray,selectedItem);
				}
			}
//				if(selectedItem == _levelTwoArray[i] && _soundManager.gameSound.playProgress != 1)
//				{
//					trace("selected item dont scale down or fade out");
//				}
			else 
			{
				TweenLite.to(_easel.alphabetContainer.getChildByName("easelItemClip"+ i), .25, {transformAroundCenter:{scaleX:.6, scaleY:.6}});
				TweenMax.to(_easel.alphabetContainer.getChildByName("easelItemClip"+ i),.25, {glowFilter:{remove:true}});
				TweenLite.to(_easel.displayDrawer.imageContainer.getChildByName("drawerItemClip"+i), .5, {alpha:0});
			}
		}
	}

Link to comment
Share on other sites

It's ok I finally was able to solve my problem. Basically I created a sprite that overlayed all the items and disabled mouse enabled, when the user selected an item I enabled the sprite preventing the items from being selected. when the sound play progress was complete I dispatched an event disabling the sprite and everything seems to work great now with out any unwanted clicks, overlapping audio and animations.

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