Adobe Dreamweaver Forums



Last 10 THreads :         Update HELL for unsupported OS... (Last Post : WTF? - Replies : 0 - Views : 1 )           »          Cannot install Flash Player 10 (not-beta) (Last Post : Darren McNally - Adobe - Replies : 8 - Views : 9 )           »          Full screen flash projector reverts to windowed whenexiting screen saver (Last Post : rbolman - Replies : 0 - Views : 1 )           »          On hitTest go to next frame? Why doesn't this work? (Last Post : kglad - Replies : 1 - Views : 2 )           »          Contribue won't allow Images to be inserted (Last Post : RiderAlberta - Replies : 0 - Views : 1 )           »          This just sucks.... (Last Post : TC2112 - Replies : 11 - Views : 12 )           »          Update from array (Last Post : -==cfSearching==- - Replies : 3 - Views : 4 )           »          PHP Notice Problem (Last Post : UteFanJason - Replies : 7 - Views : 8 )           »          Limited Ammo (Last Post : kglad - Replies : 19 - Views : 20 )           »          Icon Text sticks when returning to home page.. (Last Post : kglad - Replies : 1 - Views : 2 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Flex
 
Tags: , , ,

Reply
  #1 (permalink)  
Old 07-24-2008, 02:29 PM
NathanThibert
 
Posts: n/a
Diggs:
Default Editing ArrayCollection with Datagrid Issue

Hey everyone,

Here is the problem:

I have a master ArrayCollection and a secondary ArrayCollection that is a copy
of the master. I user the secondary AC as my dataProvider for the Datagrid. I
allow the DG to be editable. Once a user changes the data within the DG, it
updates the secondary AC and then updates the master AC. The thing is I don't
want to update the master AC. I thought if you copy a collection there is no
more reference to the master copy. How do I do this? I have tried different
ways, secondary = master, secondary = new ArrayCollection(master.source), I
even try looping through the master AC and adding each object to the secondary
and it still updated the master. I have ran out of options. Can anyone solve
this issue?

<?xml version="1.0"?>
<!-- itemRenderers\events\EndEditEventFormatter.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >

<mx:Script>
<![CDATA[
import flash.utils.setInterval;

import mx.controls.TextInput;
import mx.events.DataGridEvent;
import mx.events.DataGridEventReason;
import mx.formatters.NumberFormatter;
import mx.collections.ArrayCollection;

[Bindable]
private var master:ArrayCollection = new ArrayCollection([
{Artist:'Pavement', Album:'Slanted and Enchanted',
Price:11.99},
{Artist:'Pavement', Album:'Brighten the Corners',
Price:11.99 }
]);

[Bindable]
private var secondary:ArrayCollection = master;

// Define the number formatter.
private var myFormatter:NumberFormatter=new NumberFormatter();

private function checkCol():void {
trace(master.getItemAt(0).Artist);
}

// Define the eventlistner for the itemEditEnd event.
public function formatData(eventataGridEvent):void {
// Check the reason for the event.

var intInter:int = setInterval(checkCol, 100);

if (event.reason == DataGridEventReason.CANCELLED)
{
// Do not update cell.
return;
}

// Get the new data value from the editor.
var newData:String=
TextInput(event.currentTarget.itemEditorInstance). text;

// Determine if the new value is an empty String.
if(newData == "") {
// Prevent the user from removing focus,
// and leave the cell editor open.
event.preventDefault();
// Write a message to the errorString property.
// This message appears when the user
// mouses over the editor.
TextInput(myGrid.itemEditorInstance).errorString=
"Enter a valid string.";
return;
}

// For the Price column, return a value
// with a precision of 2.
if(event.dataField == "Price") {
myFormatter.precision=2;
TextInput(myGrid.itemEditorInstance).text=
myFormatter.format(newData);
}
}
]]>
</mx:Script>

<mxataGrid id="myGrid"
dataProvider="{secondary}"
editable="true"
itemEditEnd="formatData(event);" >
<mx:columns>
<mxataGridColumn dataField="Artist"/>
<mxataGridColumn dataField="Album"/>
<mxataGridColumn dataField="Price"/>
</mx:columns>
</mxataGrid>
</mx:Application>

Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-24-2008, 08:43 PM
ntsiii
 
Posts: n/a
Diggs:
Default Re: Editing ArrayCollection with Datagrid Issue

An assignment of anything but a primitive value, like String or int uses a
reference, and does not make a copy.

Since the values in the array are objects, you cannot use slice() on the
underlying array to get an independant copy.

You will need to loop over the array, and for each item, create a new item
object, assign its properties based on the master item.

Access the AC's underlying array through the "source" property.

Tracy

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 12:16 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk