Friday, March 16, 2007

caption... success!

I just fixed the caption problem. I'll post the successive file tomorrow. I also overwrote my ga_flashmaptest3 file, but I guess it doesn't matter since I've fixed the problem.

This involved pushing the variable "this" to the caption function and then translating the "this" information into a string, removing extra characters and some letter-case manipulation.

So now... I need to move to the next aspect to strike off my list. I need to review my desired functions again.

ga_flashmapTest4

Wednesday, March 14, 2007

Colored map and captions combined

I'm making some headway, although I haven't figured out how to get to the captions to load the right data yet. That's frustrating me.

What I do have: a new Georgia map that has all the counties converted to MCs, code that colors the counties based on their Extension district affliation, and captions that show when any county is rolled-over (with space for county name and district).

Here's the file: ga_flashmapTest2

Once again, I've reached my limit for the evening. I had a good bit of trouble adding in the captions and getting the code to recognize my buttons.

I will say that this is becoming a stronger proof-of-concept with each step. I can dig into dynamic data pretty soon.

Just a little more tweaking of the code...
I've managed to get the caption to show unique info for each button, as well as adding a rollover effect to make the chosen county more obvious. It's still not what I want, but a bit of a relief because I've almost solved my current problem.

Here's the newest iteration: ga_flashmapTest3

Just playing with this a little, I see that I need to set some sort of boundary to keep the caption box from going off the stage. I'll need to look into this.

Code and books used:
Actionscript for Flash MX, Moock
  • Character Case Conversion - .toLowerCase
  • Color Class - .setTransform

 

Sunday, March 11, 2007

Dynamic Captions

Alright! I've taken the captioning code from my Xeriscape project from last Spring and brought it into my testing environment.

This has taken some manipulation, but I've managed to create caption labels for each of my houses and also dynamically called the houses as buttons (this is crucial later).

So what? I'm using something from earlier, right? Not exactly. Before, I loaded the text for the caption and the button actions on each instance of the button on the stage. Not the case this time, which is exciting because this is a new leap for me. I've used my arrays to dynamically load the button names into a function. So, if I want to change what ALL the "house" buttons in my file do later... all I have to do is change the master function. This is a MAJOR step towards portability!

Here's the file so far: dynamicCaption

I'll try to deconstruct this a little here. All of this AS is in the first frame of my Flash file. Eventually, as I can compact it, the most essential parts will be left in the Flash file and the more editable values will be stored in an external AS file. Throughout the code you'll see "trace();", this is just a great way to check that functions are working and values are passing through the code.

First, these are the arrays that I'm loading for each of the following five variables. Right now, "county" and "countyButton" have the same information, minus punctuation (both forms are required in code further down). I'd like to be able to manipulate the quotes with AS but haven't been able to accomplish that yet.
var county = ["","/house1","/house2","/house3","/house4"];
var countyButton = ["",house1,house2,house3,house4];
var district = ["","NE","NW","SE","SW"];
var color = ["",0x7a287a,0x0066cc,0xff0099,0xffff00];
var county_district = ["","NE","NE","SW","SE"];

This is the function for the caption label. I gleaned it from an online tutorial a year ago... I can explain it later. But, I do need to load this function before I can call it. Reversing this order is a big no-no that just results in failure.
captionFN = function (showCaption, captionText, bName) {
if (showCaption) {
_root.createEmptyMovieClip("hoverCaption",
  this.getNextHighestDepth());
cap.desc.text = captionText;
cap._width = 10*cap.desc.text.length;
cap._alpha = 90;
//
if ((bName._width+bName.x+cap._width)>Stage.width){
xo = -2-cap._width;
yo = -17;
} else {
xo = 2;
yo = -17;
}
hoverCaption.onEnterFrame = function() {
cap._x = _root._xmouse+xo;
cap._y = _root._ymouse+yo;
cap._visible = true;
};
} else {
delete hoverCaption.onEnterFrame;
cap._visible = false;
}
};

This is a nested loop that assigns names to each of the MCs and then assigns color based on the MCs corresponding district. The variable in the square brackets pulls the appropriate value from the relevant array. (Say what? Ask me more if you want to know.)
var p = 0;
while (p<county.length) {
var q = 0;
while (q<district.length) {
if (county_district[p] == district[q]) {
county_color=color[q];
set_county_color = new Color(county[p]);
set_county_color.setRGB(county_color);
// trace (district[q]);
}
q++;
}
// trace (county[p]);
p++;
}

This is my test for loading the caption label per MC. It isn't quite working because it's just loading the last value for all of the houses. I think I experienced this problem earlier and need to include it in the loop above. Aside from that, I've used a new method in this section to load the caption text by dynamically manipulating data in the county string (var countyName).
var r = 0;
while (r<county.length) {countyName = county[r].substring(1,county[r].length);
trace (countyName);
countyButton[r].onRollOver = function() {
captionFN(true,countyName,this);
this.onRollOut = function() {
captionFN(false);
};
};
r++;
}
stop();

Fixing the caption labels
It looks like I need to add some sort of check so the AS knows to apply which caption value to which MC. I'll have to play with this a little to figure it out.

This is much more complicated than I thought. It looks like the code isn't creating a permanent caption associated with the particular MC. I think I may need to write something that duplicates and creates a new instance of the caption MC. That way, every county MC can have it's very own relative caption MC.

This description should help me remember what I'm trying to accomplish when I start combing my coding books.

Later...
This is just not coming together today. I've made some progress, duplicating the caption instance (here: dynamicCaption2) but I can't figure out how to get the dynamic clip's name into the caption function, it just won't go.

The MC duplication code is pretty simple. My caption MC is called "cap", for every duplication this should add a number to "cap" (cap1, cap2, etc.) and position the new clip about 20 pixels below the previous one.
cap.duplicateMovieClip("cap",p,{_y:p*20});

I'm going to have to walk away from this for now. Maybe something new will happen in a few days.

I'll work on the map later. I think there's a better version of the graphics at work. No point in turning all those counties into MCs if I'm going to need an updated file.
 

Importing parameters via external .as

I'm trying to get my mind around making this map portable and reusable. I think I can do this by importing nested external actionscript files. The main reason why I want to keep my actionscript in an external file is to enable future editing without requiring any manipulation of the .fla file.

Ultimately, what I think will work is putting the load file action on a button in the map interface. When the user presses the button, it will load whatever data the author has included in the relevant file. A master .as file would contain general functions and attributes of the map, while supporting .as files would be author specific.

I feel like I'm on to something. I'll need to investigate this and try to better define how it will work. A workflow drawing should help.

More later....