Thursday, June 09, 2005

adding rows to datagrid at run time

If you are working with an editable data grid component
and as you reach the last column you need to add the next row
so that the next set of informations can be add do this:

drag a datagrid component to the stage
make you data grid big enough since am not goin to give column width and all
into the code .

once the data is ready to send it also checks for any null rows.here I have only checked for
a specific value before deleting a row.

The context Menu helps to delete any selcted row.
once you delete a row make sure that you reflect the change in the dataprovider
and reload the entire data with the dataprovider if you want to edit the DataGrid agian.


give an instance name : myDataGrid_dg


and give some life with this action script :

---------------------------------------------------------

import mx.controls.gridclasses.DataGridColumn ;


var my_cm:ContextMenu = new ContextMenu();
my_cm.hideBuiltInItems();

var menuItem_cmi:ContextMenuItem = new ContextMenuItem("delete_handle", deleteHandler);
my_cm.customItems.push(menuItem_cmi);

this.menu = my_cm;




function deleteHandler() {
(myDataGrid_dg.removeItemAt(myDataGrid_dg.selectedIndex));
}




data_array = new Array();
data_array =[{name:"", price:"",number:""}];

myDataGrid_dg.dataProvider = data_array;

// this is the simplest way to make a DG ready

myDataGrid_dg.editable =true;


//make the DG editable
var num =0;

listen = new Object();

// a listener object is add to trigger events


listen.cellFocusOut = function(obj){
if(obj.columnIndex ==2){
num ++;
var obj ={name:"", price:"",number:""}
myDataGrid_dg.addItemAt(num,obj);
//here you can also use
//myDataGrid_dg.addItem(obj);
}
}



myDataGrid_dg.addEventListener("cellFocusOut",listen);


send_btn.onRelease=function(){
trace(myDataGrid_dg.length);
for(i = myDataGrid_dg.length ; i >= 0 ;i-- ){
if((myDataGrid_dg.getItemAt(i).price) == undefined||(myDataGrid_dg.getItemAt(i).price) == ""){
myDataGrid_dg.removeItemAt(i);
}
}

}
//each time a cell gets out of focus the event is triggered

-------------------------------------------------------------

Monday, February 14, 2005

pop up with image size

If you are making an image viewier and wnt the pop up to resize according to the image size this is wot u have to do.
I hav'nt used the loader component of flashMX 2004 which make things more simple, here am using the old techique of loading image into an empty movie clip.

to make things working open a new flash doc inside the lib'
make three movie clip.

1.boder_mc -- this will have the outer border of you image that you are showing
2.holder_mc -- this will be any empty movie clip to which you will load the image
3.loading_mc -- this movie clip will have the loading animation

once this is done drag all of them into another movie clip called frame_mc
and drag frame_mc to stage.

keep the same instance name and the order


on the one and only frame paste this code and that's it .

------------------------------------------------------------------------------------------------
var id ;
var x_range;
var y_range;
var counter =1;

function loadImage(){
frame_mc.loader_mc._visible=true;
frame_mc.holder_mc.loadMovie("test.jpg");
id = setInterval(traceAmount,100);
}

function traceAmount() {
frame_mc.holder_mc._alpha =0;
if(frame_mc.holder_mc.getBytesLoaded()== frame_mc.holder_mc.getBytesTotal()){
xrange = frame_mc.border_mc._width -( frame_mc.holder_mc._width+10);
yrange = frame_mc.border_mc._height-( frame_mc.holder_mc._height+10);
frame_mc.loader_mc._visible=false;
clearInterval(id);
id = setInterval(popupSizer,100,xrange,yrange);
}
}

function popupSizer(x:Number,y:Number){

var xdiv_val = x/10;
var ydiv_val = y/10;
frame_mc.border_mc._width -= xdiv_val;
frame_mc.border_mc._height -= ydiv_val;

counter ++;

if(counter == 10){

frame_mc.border_mc._width = frame_mc.holder_mc._width+10 ;
frame_mc.border_mc._height= frame_mc.holder_mc._height+10 ;
frame_mc.holder_mc._alpha =100;
clearInterval(id);
}
}

loadImage();
stop();

----------------------------------------------------------------------------------------------
I have used some constants , be ready to change those and improvise the look and feel of the out put.
Happy coding