Hi,
Flash CS5
Is this feasible and what is the procedure to use ?
Hope AS3 is the place to post this.
We have an excel table of bus routes indicating settlements they run to/from/through, one settlement per column, 5 columns of settlements, some columns are empty, each row is a service number.
Fictional example:-
125 Oxford Aylesbury Woking
156 Coventry Wolverhampton Birmingham StokeOnTrent
We wish the user to be able to scroll up down and maybe left right this excel table viewing it in Flash.
We need the user to be able to hover over a row and have the settlements for a route appear on the map only whilst the route in the table is hovered over. Is hover possible or would mouse click on a route in the excel table be necessary ?
Each exists as a movieclip of spot and text, instance name being the name in the excel table. Flash instance naming dislikes gaps so StokeOnTrent has to be written as such, no apostrophes etc.
We hope to convert names like Stoke On Trent into gapless names using excel then use this gapless tables contents in flash AS3 for control of visibility whilst displaying the gappy text table in the scroll pane for the user.
…or is there a better way ? Can AS3 strip out gaps and apostrophes ?
I can see how a movieClip can be made into a scrollPane with left right up/down scrolls.
How should we go about getting the excel table into the movie clip for scroll pane use with a live link so that any changes to the excel file update in the scroll table in flash ?
A non flash person will be adding bus route data to the excel table.
What if a route requires another column to indicate more settlements ?
Envirographics
Hi, thanks..
would changes in the excel table update automatically with this method ?
What if another column was added ?
How do I turn this parsed data into an MC ?
Can we convert the gappy names to gapless in AS3 ?
Would the excel table scrollpane allow hover to identify the sttmnts and make visible the MCs for them ?
Envirographics
Flash can read a xls or xlsx file, you nedd (like say Kglad) convert the file to a simple text file (save in excel as csv or using a PHP project), the you can read the new file and insert the information inside a Data Grid, where the format is defined in flash, because de data grid is a flash component
changes (including adding columns) to your excel table will update your csv file IF you publish an updated file.
parsing the csv file in flash requires you to add actionscript code and if you are not clever with your code (or cannot anticipate the changes in the csv file that might be made), you'll need to update your actionscript.
use the actionscript string/array methods, you should be able to maniuplate the data strings to suit your needs.
the data won't be parsed into a movieclip. you will probably want to display your data in flash and to do that, as mentioned by esdebon, a datagrid is usually ideal.
and the datagrid has itemrollover and itemrollout events that you can use to display additional info about datagrid items.
Hi, thanks to you both.
I read of making a horizontal scroll dataGrid, we will need vertical also, is this possible ?
As for our gappy apostrophe settlement names visible for the end user, with flash requiring gapless and apostrophe less, where can this be best dealt with and how ? If AS3 is there a simple code to do this and where in all this would that sit ?
If anyone has an example of how excel has been fed into a datagrid it would be useful to see.
Envirographics
use the flash string methods to manipulate your data.
loading a csv file and displaying the contents in a datagrid:
import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
import fl.data.DataProvider;
import fl.controls.DataGrid;
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE,completeF);
urlLoader.load(new URLRequest("Book1.csv"));
var dg:DataGrid
function completeF(e:Event):void{
var dataS:String = e.target.data;
var dataA:Array = dataS.split("\n").join("").split("\r");
var dpA:Array = [];
var itemA:Array;
for(var i:int=0;i<dataA.length;i++){
itemA = dataA[i].split(",");
dpA.push({"col1":itemA[0],"col2":itemA[1],"col3":itemA[2]});
}
var dp:DataProvider = new DataProvider(dpA);
dg.columns = ["col1","col2","col3"]
dg.dataProvider = dp;
}
p.s. don't mark your questions as helpful. mark responses that you think might help others.
Hi,
Many thanks for that coding, trying it out on gapless content initially to see that the csv data feed works...
Why this error ?
I have the code in a new Flash.fla AS3 file , file new AS3 ok then drag dropped a datagrid to stage and saved file as SimpleDataGrid_UseCSV_test.fla and created a most simple test excel file saved as simple.csv both sitting in the same folder.
Excel is three columns called col1 col2 col3 and two rows with fictional two character no gap entries per cell. A2 B2 C2 A3 B3 C3 and so on !
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///C|/DOCUME%7E1/Envirographics/LOCALS%7E1/Temp/Simple.csv
at Untitled_fla::MainTimeline/frame1()[Untitled_fla.MainTimeline::frame1 :7]
Thinking it may be lack of an instance name, I then name the datagrid instance in properties as DataGrid and test movie, address error now vanishes and instead the data grid is in bits which are flashing on and off.
Why ?
import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
import fl.data.DataProvider;
import fl.controls.DataGrid;
var urlLoader:URLLoader = new URLLoader();
var dg:DataGrid
function completeF(e:Event):void{
var dataS:String = e.target.data;
var dataA:Array = dataS.split("\n").join("").split("\r");
var dpA:Array = [];
var itemA:Array;
for(var i:int=0;i<dataA.length;i++){
itemA = dataA[i].split(",");
dpA.push({"col1":itemA[0],"col2":itemA[1],"col3":itemA[2]});
}
var dp:DataProvider = new DataProvider(dpA);
dg.columns = ["col1","col2","col3"]
dg.dataProvider = dp;
}
Envirographics.
Hi,
I do have in a folder both the fla and the csv file, csv name is Simple.csv
address is P:\C\Envirographics\Flash Projects\test simple csv datagrid
I have also now saved the fla to a new folder, then re created the csv from the xls excel file and put the csv into that new folder.
Still I get the same problem.
Compiler errors has:-
Scene 1, Layer 'Layer 1', Frame 1, Line 10 1046: Type was not found or was not a compile-time constant: DataGrid.
line 10 is var dg:DataGrid
Its in the library as DataGrid and its instance name is DataGrid
So lets start over !
File new AS3 ok
name layer1 as AS3 (layer name shouldnt make a difference but I'll do so.
select frame 1, drag drop DataGrid to stage and name it DataGrid in properties instance name.
look in lib , its there, ctrl x it off stage and drag drop from lib back to stage anyway.
Select frame 1 and hit F9, Make sure Scene 1 AS3:frame 1 selected, Paste code in.
Save fla to new folder. Create a new csv from the xls to that same folder.
test movie.
Now the datagrid is not in bits, but Compile error has 4 lines of errors.
Lets try again, same procedure and test movie, again datagrid stable but this time output error has :-
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: file:///P|/C/Envirographics%20DATA/Flash%20Projects/5th%20test%20simpl e%20csv%20datagrid/Simple.csv
at SimpleDataGrid_UseCSV_freshStarttest5_fla::MainTimeline/frame1()
Thats different from just now, looking back in on that one it also now instead has output error reading this and complier error is now empty !
Envirographics
to remedy the 1046 error, import the DataGrid class:
import fl.controls.DataGrid
and the path you mentioned in your message is different than the path mentioned in your recent 2044 error message:
P:\C\Envirographics\Flash Projects\test simple csv datagrid
is not the path in
file:///P|/C/Envirographics%20DATA/Flash%20Projects/5th%20test%20simple%20csv%20datagrid/Simple.csv
Code is:-
import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
import fl.data.DataProvider;
import fl.controls.DataGrid;
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE,completeF);
urlLoader.load(new URLRequest("Simple.csv"));
var dg:DataGrid
function completeF(e:Event):void{
var dataS:String = e.target.data;
var dataA:Array = dataS.split("\n").join("").split("\r");
var dpA:Array = [];
var itemA:Array;
for(var i:int=0;i<dataA.length;i++){
itemA = dataA[i].split(",");
dpA.push({"col1":itemA[0],"col2":itemA[1],"col3":itemA[2]});
}
var dp:DataProvider = new DataProvider(dpA);
dg.columns = ["col1","col2","col3"]
dg.dataProvider = dp;
}
and there is a DataGrid in the lib and it exists on stage. It has no instance name in properties.
test movie and I get in Output tab :-
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at SimpleDataGrid_UseCSV_test4_fla::MainTimeline/completeF()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
If I then name it in properties instance as DataGrid and test movie, I instead get:-
data grid as bits flashing and
Scene 1, Layer 'AS3', Frame 1, Line 10 1046: Type was not found or was not a compile-time constant: DataGrid.
Envirographics
The fact that I had tried both DataGrid and dg in instance name and failed seems odd, as dg now works. The code could do with some extra 'you need to also ensure' notes.
Success ! Thanks.
we have seen a 1046 error, a 2044 error and a 1009 error and thats with all elements being in place, the only thing not right was the instance name. One instance name throwing out red herrings.
It is so odd there is nothing on the www on csv into DataGrid.
Now to try the coding for blank cells and gappy entries.
Envirographics
One hurdle over, another one faced. This code you supplied was to remove gaps and populate a dataGrid from an excel table saved as csv. It works without gaps so far. Adding another row of data to excel and saving as csv sees flash fail to show additions, even altering cell data. Then I experienced movie failure in another test.
update to findings...if I close down Flash and relaunch it then run the fla again, it then works.
FURTHER UPDATE...no it doesnt on the next file I try, unable to get Flash test movie to show anything but the swf it creates when I run that from windows explorer DOES show the changes.
so why does an update to the csv file with flash running cause test movie to fail ?
To see just what was happening.....
csv file changes make or break Flash. why ? (using option in excel called comma delimited, not macintosh csv )
If I open the excel file from which Simple.csv was made and remake the csv without altering any data the Flash movie then fails, if I reinstate the original Simple.csv it works again.
Prior to this discovery on the original code taken from your posting, on a different test yesterday I had firstly renamed the dataGrid on stage in instance as MyDataGrid and then also right clicked on it in lib and went properties and named it there as MyDataGrid.
On the latter I did get a warning 'this symbol wont support frame scripts' and clicked Ok.
File still worked.
Code is:-
import flash.net.URLLoader;
import flash.events.Event;
import flash.net.URLRequest;
import fl.data.DataProvider;
import fl.controls.DataGrid;
var urlLoader:URLLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE,completeF);
urlLoader.load(new URLRequest("Simple.csv"));
var MyDataGrid:DataGrid
function completeF(e:Event):void{
var dataS:String = e.target.data;
var dataA:Array = dataS.split("\n").join("").split("\r");
var dpA:Array = [];
var itemA:Array;
for(var i:int=0;i<dataA.length;i++){
itemA = dataA[i].split(",");
dpA.push({"col1":itemA[0],"col2":itemA[1],"col3":itemA[2]});
}
var dp:DataProvider = new DataProvider(dpA);
MyDataGrid.columns = ["col1","col2","col3"]
MyDataGrid.dataProvider = dp;
}
Saved it by a new name to a new folder. 6th test_DataGrid_csvWithGaps
Now to test this degapping code. I then added to the names of the first row of excell cells so they read A1 a B1 b C1 c and save file as SimpleWithGaps.xlsx saving to that new folder and then did a save as SimpleWithGaps.csv and save also to the same folder.
I altered the csv name in the code to SimpleWithGaps.csv
test movie
it failed
Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: #file:///P|/C/Envirographicsfile:///P|/C/Envirographics%20DATA/Flash%20Projects/6th%20test%5FDataG rid%5FcsvWithGaps/SimpleWithGaps.csv%20DATA/Flash%20Projects/6th%20test%5FDataGrid%5FcsvWithGaps/SimpleWit hGaps.csv
at SimpleDataGrid_UseCSV_freshStarttest6gaps_fla::MainTimeline/frame1()
Try it out on the dg code pasting across to that folder the csv file and it worked. Try again on the 6th test folder altering lib property back to DataGrid and it worked, altered that to MyDataGrid and Ok the frame scripts warning and it still workd ! why did it fail ? this is so weird.
Code and csv seems very easily upset or is it just my luck !
Envirographics
so why does an update to the csv file with flash running cause test movie to fail ?
Answering my own predicament, after much tribulation and hours lost, here is the answer.
Its Msoft Excel 2007 at fault. It needs to be closed down before running Flash ! Save as csv sees the xlsx file that was open now with file type csv and whilst thats open in Excel it wont let Flash perform the test movie and display the result correctly.
same happens in Arcmap when Excel is in use for it, I am informed. is this Msoft at fault ? I had to reboot PC so as to delete a folder with excel files in, as despite all progs closed, it insisted the folder was in use !
Envirographics
North America
Europe, Middle East and Africa
Asia Pacific