Can I invoke a timeline from an external text file Array?

This is a discussion on "Can I invoke a timeline from an external text file Array?" within the Flash & Multimedia Forum section. This forum, and the thread "Can I invoke a timeline from an external text file Array? are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Flash & Multimedia Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Mar 31st, 2005, 13:12
New Member
Join Date: Mar 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Can I invoke a timeline from an external text file Array?

Hello all, forum newbie here! Not only that, but I'm also pretty new to intermediate Actionscript too so please please please, talk to me as if I were a four year old! Now my problem

I'm stuck. I am creating a presentation for a friend who works in the field of science. I've promised results before Friday :eek: I'm trying to get Actionscript to engage a timeline effect from an external text document containing specific data in an array format. So basically I have created a map of London divided by its postcodes eg: NW2, SE12, E2... Graphically, there are two layers to this representation of London, a complete map of every postcode in London grouped together in light grey beneath (see pic1), and on top a layer with each seperate postcode created as an individual movie with an alpha state of 0 (as in named by its instance as the postcode it represents) which, when triggered by the array is highlighted in red on the map (see pic2).


pic1


pic2

Sorry about the pictures but thought it's the best way to explain what I mean! I have some script I got from Flashkit to trigger the data from an external file to highlight corrosponding areas of london by its postcode.

Below is an example of the data in the external text document:

Code: Select all
estados1=
estados2=
estados3=N15=
estados4=
estados5=
estados6=
estados7=
estados8=N22=
estados9=SE1=
There is more data than that I want to represent, 153 lines of it to be exact (152 including zero). This is the actionscript from the movie:

Code: Select all
dir = new LoadVars();
dir.load("thedata.txt");
dir.onLoad = text;
function text() {
	adjustment = new Array();
	adjustment = dir.estados1.split("-");
	tamano = adjustment.length;
	for (i=1; i<=tamano; i++) {
		color = new Color(adjustment[i-1]);
		map = new Object();
		map = {ra:0, rb:120, ga:0, gb:0, ba:0, bb:0, aa:50, ab:0};
		color.setTransform(map);
	}
}
Now, the movie works except that it does not invoke a timeline at present. That is to say, I want to have the data from the text document load over a period of time. "estados1" should be what is represented on the map for frame 1 and "estados2" for frame 5 "estados3" for frame 10 etc (although ideally I would like to have it be a smooth transition so that if postcode EC1 is being introduced from the external data file it fades in and then fades out before the next set of data is represented). At the moment what happens is that the movie simply loads everything in in one chunk, every postcode is there. My friend would like to see it develop on screen in realtime. Does anybody here have any suggestions? Any help would be appreciated

d-kam.

EDIT: Forgot to explain that "estados*" is a consecutive day reference so in effect the movie has 153 days in it. I hope this all makes sense!

  #2 (permalink)  
Old Mar 31st, 2005, 22:02
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
Hi and welcome to the site!

What you're asking is certainly not an 'intermediate' question! It's pretty difficult stuff in Flash.

Mixing Actionscript with the timeline in a dynamic way is quite difficult, for various reasons. I would instead suggest that you put the map parts into one containing movieclip. You can then put certain Actionscript onto this movieclip that can act based on time, in a way.

The following code can be placed on a movieclip:
Code: Select all
onClipEvent (load) {
// initialise stuff
}
This can be used to setup variables, etc and is run first but only once.
Code: Select all
onClipEvent (enterFrame) {
// main work done here
}
This code is run on every frame. So based on your FPS you could easily get this to do time-based animation.

If you're feeling confident you could write a function to try to fade in and out all of the areas individually, but I think it would be easier to have each in it's own movieclip that fades to a highlighted colour and back again. Then your script only has to tell each clip to play and it'll fade in, or out, depending on where it is already.

There might be better ways to do this, but I can't think of any immediately. What you're doing is a little odd and I think that if you told us exactly what you were trying to achieve it might be easier to do another way.

Let's say you want certain areas highlighted at different times... why not simply let the user click on the areas to highlight them and have a 'reset' button to clear all the areas back again. You could even hard code this to highlight certain groups, etc, etc. I don't think that would be unreasonable for a presentation?

If whoever you're making this for wants to change the animations for different presentations then another idea might work. What about defining a time for each postcode as well in your source? In Flash, all you need to do is run the same script every x seconds, or when the user prompts, to move onto the next timeframe. If each postcode has a timeframe then you just scan through the list and highlight the appropriate areas.

I can't help thinking that it would be easier to just preset the animations into Flash in the first place? Fiddling around with text files and getting the programming to work will probably take more time in the long run.

From my experience, presentations aren't dynamic anyway. The way you have this setup already makes it fairly easy to create a hardcoded version that simply runs the same script you already have at particular places on the timeline - unless you have a really good reason not to?
  #3 (permalink)  
Old Mar 31st, 2005, 23:03
New Member
Join Date: Mar 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks you for your answer and warm welcome Sirkent! I think I need to re-explain what my problem is because I'm not sure if I explained it properly, although I'll definitly look into your suggestions I'll start from the top:

Movie objectives:

1: To create a flash movie that can process a large amount of data from an external file.
2: To have that processed data trigger movie events within the flash document.
3: To make it look cool!

Movie specifics:

-The data is actually confidential so I need to use an alternative for what it represents. I'll use rabbit populations for this purpose!
-The main element for each movie is a map of London divided into postcodes. The map was created by myself by vectorising and cleaning up a jpeg I got off the net. I then broke this vector up and turned every postcode area into a movie and named it by its relevent postcode. The postcodes are the target for what the data represents, which as I said are *ahem* rabbit populations and in this case I want to represent which postcode/s had the highest populations for a given day/date. There will some days/dates that return no results.
-The data was generated using excel and is in the following format

Code: Select all
estados1=NW1
estados2=NW2
estados3=NW3
//where estados* is equal to a date and NW* equal to the rabbit population data for that day.
(Please note: this format can easily be changed to suit any actionscript requirements).

-The data needs to be shown over a period of time so that for each given day, the populations are shown for a specified period of time and then dissapear when the next day is processed.
-A date for the data needs to be included within the movie relevent to the day for data shown on the map (so that estados1 would be 11th October 2004 for example). (I was just gonna do this myself by hand by putting a text box with the date in each frame and then sync it to the output of the data).


That's it really. I can see how this probably a tall order for flash and am wondering if I should try out something else but it is for the visual effects in flash that I would like to use it, not its ease of use.


Now to explain what I have. Here is the file with a sample of data called 'data.txt'. I got the code from flashkit.com from someone elses movie which seemed to offer exactly what I need except a timeline and the ability to read multiple lines of data... OK, so maybe not exactly what I needed but it seemed close! So this is what I am using as a script:

Code: Select all
dir = new LoadVars();
dir.load("data.txt");
dir.onLoad = text;
function text() {
	adjustment = new Array();
	adjustment = dir.estados1.split("-");
        setInterval( text, 1000 );
	tamano = adjustment.length;
	for (i=1; i<=tamano; i++) {
		color = new Color(adjustment[i-1]);
		map = new Object();
		map = {ra:0, rb:120, ga:0, gb:0, ba:0, bb:0, aa:50, ab:0};
		color.setTransform(map);
	}
}
It's great in that it will read the data, but not great in that it only outputs the results all in one go. Is there any other way it can do this? Any adjustments including completelty scrapping the original AS if someone has a better suggestion would be very welcome. I hope this is clearer! If not please let me know.

Many thanks,

d-kam.
  #4 (permalink)  
Old Mar 31st, 2005, 23:16
New Member
Join Date: Mar 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Forgot to say, yes the presentation doesn't need to be dynamic and will be hardcoded. It only needs to play, stop and start again. However the ability to change the data in the presentation by simply updating an external file would be extremely useful I'm looking into your suggestions now btw Sirkam.

d-kam.
  #5 (permalink)  
Old Apr 1st, 2005, 00:52
New Member
Join Date: Mar 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
OK, so I think I've decided on something for this movie but need some more scripting advice please

Quote:
Then your script only has to tell each clip to play and it'll fade in, or out, depending on where it is already...
This sounds like the best option to me, but what would be great is if I could have some simple AS imbedded into the external file control the timeline something like this:
  • -Script tells flash to load movie clip(s) such as instanceName.gotoAndPlay(2);
    -Script tells flash to wait a given amount of time before reading the next line of data for example using setInterval
    -Script repeat the above process for the consequent line of data.

The only thing is, I don't know how to make the external text doc communicate with flash. Could the data output commands such as...

Code: Select all
day1=WC2.gotoAndPlay(2) NW1.gotoAndPlay(2) setInterval:1000
day2=SW3.gotoAndPlay(2) setInterval:1000
...and be happy with it? Obviously, the AS is not correct there I am only guessing. But am I going along the right tracks?

d-kam

PS: Sorry about all these posts! I hope you guys don't mind...
  #6 (permalink)  
Old Apr 1st, 2005, 09:25
Most Reputable Member
Join Date: Jul 2003
Posts: 1,856
Thanks: 0
Thanked 0 Times in 0 Posts
You couldn't import AS like that. If you wanted to import the code as well as the data then they would have to be in seperate files and then... what is the point?

You will simply need to specify variables in your data file, like this:
Code: Select all
&day1_1=WC2
&day_1_2=NW1
&day_1_total=2
&day2_1=SW3
&day2_total=1
That would be the easiest way... &variable=data is how variables can be easily imported into Flash using loadVariables. You wouldn't necessarily have to use a day_x_total variable, you could write the Flash to figure out how many variables there are for each day if you like, but I think you would need to do it like above, or perhaps:
Code: Select all
&day1=WC2, NW1
&day2=SW3
use a delimited approach and split each one into an array when in Actionscript.

If you have each day on a seperate row, then you can even try something a little clever like this:
Code: Select all
&data=day1, WC2, NW1
day2, SW3
Then you can tell AS to split the days into an array by looking for the delimited \r\n (the end of line character). Then within each one you can easily get the next postcode by splitting by the commas.

There's just a few ideas there, but you will need to use Flashvars, or XML in order to import your data and Flashvars using these methods is closest to what you've already shown me.

However you will, of course, have to write the actionscript to use this data in Flash, you can't put it in the file with your data, at least, not as far as I'm aware. The only way of doing it would be to actually write an interpreter to process your commands and that would be particularly difficult!

If you do want to do things such as gotoAndPlay(var) then you could also use the above...

Just remember that the last variable on a line will have \r\n on the end of it.

Also, sorry for literally expressing the development of my ideas in the post, but I think it follows through and should teach you about loadVariables and a good way of implementing them for this approach?
Closed Thread

Tags
invoke, timeline, external, text, file, array

Thread Tools

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scrub external SWF timeline and video within that SWF HeayyPops Flash & Multimedia Forum 0 Oct 15th, 2007 22:46
Load External .JS File Before Anything Else tox0tes JavaScript Forum 1 Jul 10th, 2007 14:03
Is it possible to use an external text file for a variable AdRock JavaScript Forum 2 Sep 15th, 2006 17:25
Load .swf file with External text in Another Flash document ien Flash & Multimedia Forum 3 Aug 31st, 2006 14:29
loading external images into array geminity Flash & Multimedia Forum 2 Feb 14th, 2005 21:29


All times are GMT. The time now is 16:42.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43