PDA

View Full Version : ActionScript - quick syntax question


Spudhead
12-13-2003, 04:29 PM
Well, it's actually two questions. But they're kinda related.

Anyway - I stuck this in here, I dunno how many Flash heads we get in here or if any of youse are into your ActionScripting, but I'm an ASP coder who's suddenly found himself needing to build a Flash shopping cart. :confused:

I've found a couple of references, and... well, it's ugly as hell but it's kinda like javascript, innit?

So - question one; string concatenation. IS the concatenation operator "+", same as javascript? ie:

var1="hello";
var2="world";
var3=var1+" "+var2;

Next question - variable name concatenation. I'm not sure how to describe this.... it's like eval() I guess...

OK, I've got some stuff coming in via the querystring. Let's say it looks like this:

ts1=MensTShirt&ts1_size=XL&ts1_color=red&ts2=LadiesTShirt&ts2_size=M&ts2_color=blue

The pattern there is fairly clear. Each tshirt has a name, size and color. But it could have any number of tshirts in.

I want to loop through the querystring, getting values out. Like:

for (i=1;i<someNumberIllWorkOutWhenIGetThere;i++){
myTshirtName=ts+i;
myTshirtSize=ts+i+"_size";
myTshirtColor=ts+i"_color";
}

Now I hope that want I want the code to do is clear: drop whatever value is contained in "ts1" (or ts2, or ts3, or tsn) into the variable "myTshirtName". But what I'm likely to get, I think, is either myshirtName="ts1", or an error.

And, uh, a third question.... is there anywhere out there that does the job of SoYou'reAnASPDeveloperWhoNeedsToStartMessingAboutWithActionscript.com

?

Thanks guys.

Boberto
12-16-2003, 08:13 PM
I can't really help you with my limited knowledge of actionScript, but I can provide a link to a good tutorial site. :)

http://www.actionscript.org

That one is good for learning syntax. Another good place for learning Flash is Flashkit.com.

http://www.flashkit.com

delamina
12-20-2003, 07:02 PM
So - question one; string concatenation. IS the concatenation operator "+", same as javascript? ie:
yes, that's correct.
Next question - variable name concatenation. I'm not sure how to describe this.... it's like eval() I guess...
close - eval() will work (and you'll need it) in some situations, but here i would use [ im taking it for granted you are using a LoadVars object???] the array access operator

// create a container
var dataContainer = new LoadVars();
// method to call when data loaded
// when loaded the data will be in the LoadVars object like
// dataContainer.ts0="blah";
// so we can refer to it in the onLoad function as 'this.varname'
// note: NO PARENTHESES AFTER FUNCTION NAME!!
dataContainer.onLoad = dataLoaded;
// load the data
dataContainer.load("http://blah.blah.blah/script.asp");
//
// define method for onLoad
function dataLoaded() {
for (i=0; i<this.someExtraVarContainingNumberOfRecords; i++) {
// this refers to the object calling the method (dataContainer)
myTshirtName = this["ts"+i];
myTshirtSize = this["ts"+i+"_size"];
myTshirtColor = this["ts"+i+"_color"];
}
}
like that, hope its clear enough!