PDA

View Full Version : List onclick go to the top


whisher
11-06-2009, 01:55 PM
Hi.
I've got this script and
it works fine if you click on a clip
the clip goes to the top and the others change
position with a nice tweening.

I'm wondering if there is a better
way to set up the effect.


package com{
import caurina.transitions.Tweener;
import flash.text.TextFormat;
import flash.display.*;
import flash.events.*;
//import flash.events.MouseEvent;
import com.XmlProducts;
public class Products extends Sprite {
private var _productsData:XmlProducts;
private var _active:String= 'product-1';
public function Products() {
_productsData= new XmlProducts();
_productsData.addEventListener(XmlLoader.ON_COMPLE TE, _createUI);

}
/*
public function setActive(action:String) {
_active= action;
}*/
private function _createUI(event:Event) {
var item:Object=_productsData.item;


var containerProducts:Sprite = new Sprite();
containerProducts.name= 'container';
containerProducts.x = 75;
containerProducts.y = 0;
var productPos:Number= 0;
for(var indexProduct:String in item.products.mcs){
var product:Product = new Product();
product.id= indexProduct;
product.buttonMode=true;
product.mouseChildren=false;
product.name = item.products.mcs[indexProduct].name;
product.placeholder.text = item.products.mcs[indexProduct].placeholder;
product.label.text = item.products.mcs[indexProduct].label;
product.content.text = item.products.mcs[indexProduct].content;
product.x = 0;
product.alpha = 1;
product.y =productPos;
product.height=50;
product.addEventListener( MouseEvent.CLICK, _onClick);
productPos+=product.height;
containerProducts.addChild(product);
}

addChild(containerProducts);



}
/*++++++++++++++++++++ EFFECT ++++++++++++++++++++++++++*/
private function _onClick(e:Event):void{
var containerProducts:Sprite= getChildByName('container') as Sprite;
var id:Number= Number(e.target.id);
var productPos:Number= 50;//
for(var i:Number = 0; i<containerProducts.numChildren; i++){
var product:Product = containerProducts.getChildAt(i) as Product;
if(id==i){
Tweener.addTween(product,{y:0,time:1, transition:"easeInOutSine"});
}
else{
Tweener.addTween(product,{y:productPos,time:1, transition:"easeInOutSine"});
productPos+=product.height;
}
}

}


}
}


Bye.