ActionScript 3.0 XMLSockets are a pain…

17 02 2010

You can find my code from today here, and yesterday’s here.  Compared to the ease of making Processing talk to Flash in AS2.0, AS3.0 is a nasty, hairy spider with knives for legs sitting on my laptop.  Laughing at me.  Seriously, I keep getting error after error, the most recent (and most confusing) one is:

Connection successful
ReferenceError: Error #1069: Property split not found on flash.events.DataEvent and there is no default value.
at FlashSocketAS3_fla::MainTimeline/dataHandler()

Why can’t it find the split() function?! (The split function allows me to take my string of “1,1,7.83457,1,2,8.34985,1,3,7.68472″ et cetera and easily separate it into the sensible pieces from which it’s made, namely: {integer, integer, long float decimal value} repeated 850 times for each point on my Processing video feed.)  And I don’t know what’s up with the “no default value.”  Grr.  I really, REALLY don’t want to have to draw my circles in AS2, but if I can’t figure this out, I may have to.

WHY?!  I will go get my peanut butter and other essential groceries and look at this again upon my return. X(

UPDATE: Several hours and crashes later (luckily I save before running anything)… I’ve given up on AS3.o for the moment, and am attempting to draw circles in AS2.o via a method that is pretty clean.  So far, I have a curious set of densely compacted concentric circles that meander back and forth across the stage in no pattern I can discern, but correctly in time with the socket data Processing is sending (every second, via the delay function).  I think I need to figure out how to determine the stage size (I’m using the createEmptyMovieClip(String name, int level) method.  The function below is the one I’m working on at present, trying to use the data from the socket (correctly sorted into rArray, xArray, and yArray, each an array of radii, x-coordinates, and y-coordinates) to draw the corresponding circles that my Processing sketch gives me.  See Processing Circles and Flash Circles.

function drawMask() {

this.createEmptyMovieClip(“clip”,0);

with(_root.clip) {

.beginFill(0×000000);

for(i=0; i<rArray.length; i++) {

drawCircle(rArray[i], xArray[i], yArray[i]); //radius, x, y

trace(“circle drawing works!”);

}

endFill();

}

}





Back to Basic (not quite).

16 02 2010

Is that joke still funny when talking about coding?  I’m in Actionscript 2.0 (because the xml socket code I’m using works in 2.0 and not 3.0 and at this point I’m not going into equine dentistry).  It’s been a little while since I wrote for-loops and traversed arrays and such, but so far, so good, in the sense that what I’m coding and what Flash is doing seem to correlate.  It doesn’t seem to like some parts of my code (most noteably the for-loops traversing the array)…

UPDATE: the loop works; it doesn’t like using an array length property as the ending condition, and I really need to down-clock all of the socket operations (maybe put them into an enterframe sort of context), as Flash crashed when I tried to make it do a loop from 0 to 1345.  :(  I’ll post my code as a text file in a bit.

UPDATE: The incoming data make sense, at least!  I’ve put a massive delay into the Processing side of things, so I can see what I’m doing in Flash, so to speak.

UPDATE: I feel like an idiot.  I’ve been trying to display things that don’t actually exist, so its no wonder that I’ve been getting “undefined” over and over!  Fixed that; and I’m getting the right data at the right speed! :D

UPDATE: I’m going to find a way to make Processing talk to Flash in Actionscript 3.0 if it kills me!  No way am I drawing circles in 2.0; the solutions I’ve seen for that so far are painful to behold!  I take pride in being a rather lazy person; that is, I have no desire to take the long route, even if it’s flatter.  Let me at the short, steep, prickly, difficult route!  (Random tangenital yet pertinent example: French pronouns: if asked, <<Est’ce que tu as donné les fleurs qui sont arrivées aujourd’hui à ta mère?>> “Have you given the flowers that arrived today to your mother?” I respond, <<Oui; je les lui ai donné,>> “Yes; I’ve given them to her,” not <<Oui, j’ai donné les fleurs qui sont arrivées aujourd’hui à ma mère.>> “Yes, I’ve given the flowers that arrived today to my mother.” While learning the French pronouns and their proper use was difficult at first, knowing how to use them made everything from that point on much easier.  They used to call me the Pronoun Queen in that class… a friend even made me a paper crown saying as much—in French, of course!)

UPDATE: Code as of tonight.  (Downloads as a rtf file.)








Follow

Get every new post delivered to your Inbox.