Actionscript issue: Flash 6 vs. Flash 7
March 17, 2004 4:58 PM   Subscribe

Flash Actionscript issue: I have a flash menu, with a series of links dynamically assigned using item.onRelease = function(link) {getURL(this.link);}; They work fine in flashplayer 7, but not at all in flashplayer 6. [a lot m.i.]

It is a modular menu maker, in which each menu topic is loaded like so:

onClipEvent (load) {
var title = "CULTURA GRÁFICA ";
var items = new Array("Reseña Histórica ", "La imprenta en Chile y América Latina ", "¿Cómo nace un impreso?", "Nuevas tecnologías", "Diccionario Morgan", "Colaboración Permanente");
_root.populate(this, title, items);
}

where 'title' is the section text and each element of 'items' is a sub-section. and the 'populate' funtion includes the following:


item.link = title.split(" ")[0]+i+".htm";
item.onRelease = function(link) {getURL(this.link);};

which creates a URL of the form title0.htm, title1.htm, etc.

In the test file, mouse over "Acerca de Morgan" and click on "Resena" or "Ubicacion / Contactenos". They should both open a different page.


This works alright in Flashplayer 7, not at all in 6. I assume there's some issue with getURL, but have not been able to figure out why or how to fix it. Posted on various newsgropus, support sites, searched google, etc., to no avail.
The source is here. Code here, with the getURL part marked.
posted by signal to Computers & Internet (7 answers total)
 
What version of flash are you using? Could the answer be as simple as exporting the SWF so that it is compatible with a lower version of flashplayer?
posted by banished at 5:11 PM on March 17, 2004


Response by poster: I'm using Flash MX 2004. If I export por flashplayer 6, it doesn't work in any player at all. I tried exporting for Actionscript 1 and 2, with the same (bad) results.
posted by signal at 5:22 PM on March 17, 2004


item.onRelease = function(link) {getURL(this.link);};

This line doesn't make sense to me: when making a function definition, you CAN include a variable inside the parenthesis:

test = function(someVar) { trace(someVar); };

And then you can call the function like this:

test("pancakes!!!");

Which will output the word pancakes in the Output window.

But in your case, you're never explicity calling the function stored in onRelease. That function is being called by the system, when the user releases the mouse button.

So how can the variable called link ever be given a value?

It's true that you do have a variable called link, which is part of the item object (item.link), but that's a GLOBAL variable. Any reference to a variable inside the parenthesis after a function definition is a LOCAL variable.

I don't get how this even worked in Flash 7.
posted by grumblebee at 5:29 PM on March 17, 2004


Response by poster: grumblebee:
the variable is defined as 'item.link', which is the same as item[link], where 'item' is the temporary ID of each 'button' element, as it's created. This was neccesary (I think) because the variable 'link' will change as the entire menu structure is populated. I'm still a little fuzzy on scope and functions in Actionscript, so any clarification would be much appreciated.
If it's not a huge hassle, how would you re-write this?

item.link = title.split(" ")[0]+i+".htm";
item.onRelease = function(link) {getURL(this.link);};


Thanks.
posted by signal at 5:37 PM on March 17, 2004


link = "blah blah blah";

item.onRelease = function() {getURL(link)}

===

If you want to program Actionscript (or any other language), it's VITAL that you gain a clear understanding of scope. I wish I could explain it all to you here, but it would mean a really long post, which I don't have time to make.

Check out "Actionscript for Flash MX, the Definitive Guide" by Colin Moock, and read the section on scope!
posted by grumblebee at 5:46 PM on March 17, 2004


Response by poster: Ok, this works:

link = title.split(" ")[0]+i+".htm";
item.onRelease = function() {
getURL(link);
};


So, grumblebee, you saved my butt, and if you ever need a place to crash in Santiago, Chile, let me know.
posted by signal at 5:54 PM on March 17, 2004


No problem. Chile, huh? Sounds great about now. We're having a snow storm here in NYC.
posted by grumblebee at 6:08 PM on March 17, 2004


« Older Does this motorcycle magazine exist?   |   How popular is the Atkidn Diet outside the US? Newer »
This thread is closed to new comments.