View Full Version: Actionscript 3

lassie >>Discussions >>Actionscript 3


<< Prev | Next >>

fatbuoy1- 04-03-2008

I don't follow what you mean, but regardless Basically I would like that when I pick up the picture, move it, then let go, it wont just stop dead... it will slide on a little based on the momentum of my mouse? I've seen various ball-throwing examples... just can't figure out where to start with it. Haha!! You CAN write getter/setters outside of a class architecture. Did your eyes glaze over a little when you wrote that? :D Right... I can see WHAT getters/setters can do, I don't quite understand HOW yet but i'll try implementing them and no doubt it will all become clear! :D By the way, if you look at my site you'll see the photo's are being distorted by their rotation, getting jaggy etc... is there any way of reducing that (besides not rotating them :P) and getting better, smoother quality?

bigmac- 04-03-2008

Basically I would like that when I pick up the picture, move it, then let go, it wont just stop dead... it will slide on a little based on the momentum of my mouse? I've seen various ball-throwing examples... just can't figure out where to start with it. A good place to start would be finding tutorials and/or demo files of the type of thing you're thinking of. I know they exist en-mass on the Internet. Even looking at an AS2 example would show you the logic patterns you're trying to use. But of course, I'm partial to my own roots which I think is the best way to learn... tinker. And think creatively. If you log the dragging picture's previous position each frame, then you start to have a picture of it's motion pattern. That kind of information can tell you how fast it's moving and in what direction. When the picture is released, it can continue that motion trend with a deceleration factor that adjusts it's speed by -X each frame. This stuff does not require advanced physics. All it is is creative thinking with some ultra-simple math. Did your eyes glaze over a little when you wrote that? :D No... my brain had just misfired surrounding the requirements of using getter/setters. They are required to be public members of a class, although that was a moot point in this circumstance because everything in a timeline script is public. By the way, if you look at my site you'll see the photo's are being distorted by their rotation, getting jaggy etc... is there any way of reducing that (besides not rotating them :P) and getting better, smoother quality? Naw, Flash sucks at on-the-fly bitmap rotation... just like every other application that does it. I just avoid using rotation with bitmaps whenever possible. I think you might be able to fake-smooth it with some of the scale9Grid stuff, but I don't know how it works. Look it up in Flash help.

fatbuoy1- 04-03-2008

Ah I see what you mean, basically treat everything like a mechanics problem? That was one part of maths I njoyed actually :D Sorry to bombard you, but I'm still having trouble with my arrays. Im trying to create an array for the slides nodes, then push that array into the main portfolioData array along with all the other project info. The idea is that I can then call an image's url by tracing portfolioData.slidesData... I think! heres what I have so far... //Load list of example images trace("XML File Loaded"); var xmlData = new XML(evt.target.data); // specify a node name to read as a list var projectList:XMLList = xmlData.project; // Iterate through the list of image nodes for each (var projectNode:XML in projectList) { // extract each node's data var t:String = projectNode.title; var d:String = projectNode.description; //HERES WHERE I TRY TO PUT THE SLIDE NODES INTO THEIR OWN ARRAY var slidesList:XMLList = xmlData.project.slides; for each (var slidesNode:XML in slidesList) { var u:String = slidesNode.url; var st:String = slidesNode.title; var c:String = slidesNode.caption; slidesData.push({url:u, title:st, caption:c}); } // Add data elements as a new Flash object in array portfolioData.push({title:t, description:d, slides:slidesData}); } for (i = 0; i < portfolioData.length; i++) { createButtons(); } Any suggestions/corrections greatly appreciated as always! :D Im going to give these getter/setters a bash in the meantime.

fatbuoy1- 04-03-2008

Hmm... seems those getter/setters can't be put inside another function.

Matt Kempke- 04-03-2008

This is professional ... i can tell from the fact that I feel stupid when I look at your codes :)

bigmac- 04-03-2008

Hmm... seems those getter/setters can't be put inside another function. No, they can't. Getters/Setters ARE functions. They are only special in the regard that once they are set up, you can access them like properties; as in: targetObj.getSetMethod = "sfoo"; trace(targetObj.getSetMethod); rather than: targetObj.getSetMethod("sfoo"); trace(targetObj.getSetMethod());

bigmac- 04-03-2008

And as for this script: //Load list of example images trace("XML File Loaded"); var xmlData = new XML(evt.target.data); // specify a node name to read as a list var projectList:XMLList = xmlData.project; // Iterate through the list of image nodes for each (var projectNode:XML in projectList) { // extract each node's data var t:String = projectNode.title; var d:String = projectNode.description; //HERES WHERE I TRY TO PUT THE SLIDE NODES INTO THEIR OWN ARRAY var slidesList:XMLList = xmlData.project.slides; for each (var slidesNode:XML in slidesList) { var u:String = slidesNode.url; var st:String = slidesNode.title; var c:String = slidesNode.caption; slidesData.push({url:u, title:st, caption:c}); } // Add data elements as a new Flash object in array portfolioData.push({title:t, description:d, slides:slidesData}); } for (i = 0; i < portfolioData.length; i++) { createButtons(); } It's got more problems than a one-legged man in an ass kicking con-*test*-('"). Sorry. :P The botch is in the place where you have your all caps comment about putting the slides into their own array. Two things... First, this line: var slidesList:XMLList = xmlData.project.slides; You're trying to pull data at a document level while trying to target a specific node. That line of code does not reference a specific project node to look for a <slides> list within. So, you need to reference the current node of the project iteration as the location of a slides list... as in: var slidesList:XMLList = projectNode.slides; Other problem: you're trying to push data into an array that was never created, which probably results in an 1120:undefined-target error, right? Very simple fix: create the array before trying to add data to it. So, the working script should be something like this: var slidesData:Array = new Array(); var slidesList:XMLList = projectNode.slides; for each (var slidesNode:XML in slidesList) { var u:String = slidesNode.url; var st:String = slidesNode.title; var c:String = slidesNode.caption; slidesData.push({url:u, title:st, caption:c}); } Also, I don't see anywhere that you're created the "portfolioData" array either, so be sure you've spawned that as well.

fatbuoy1- 04-03-2008

you're trying to push data into an array that was never created Ah no I had actually created those arrays already, they're up at the very top of the script, I figured various functions were going to need to reference them so I needed them to not be a part of any function... though maybe my thinkings a bit fuzzy there! I changed the Im currently fiddling about with trying to work out the speed my mouse moves at.. quite fun to try and work it out myself actually! I'm also thinking I might start looking into classes... I imagine my script would be a lot better structured if I had a class for loading and parsing the XML, a class for making the images draggable etc.

bigmac- 04-03-2008

Ah no I had actually created those arrays already, they're up at the very top of the script, I figured various functions were going to need to reference them so I needed them to not be a part of any function... though maybe my thinkings a bit fuzzy there! That's fine for portfolioData, however you WILL need to create a new array during each <project> iteration for slideData... otherwise the array will persist between cycles and accumulate every slide from every project. Im currently fiddling about with trying to work out the speed my mouse moves at.. quite fun to try and work it out myself actually! Yeah, it's fun stuff. I had a good time writing a bunch of mouse tracking for the AOL elections map I was doing last fall. Here's some food for thought for you... set up a timer for tracking mouse movement along with an array that has, oh, say ten positions. On each timer cycle, stack in the mouse's current position and pop out the oldest element. This keeps a running record of the mouse's last ten movements. You can then average the distance between each point to get the mouse's average speed, or the angle between each point for its direction. What's also cool is that you can make this system more or less precise depending on how many records you store in the array. The more records you store, the less sensitive the mouse tracking becomes. This unbelievably simple trick is actually the cornerstone to a bunch of simple game AI. Ever wonder how you make the computer beatable at Pong? That's how. You can set a sensitivity level as to how many previous ball positions to average to dilute the precision of the computer's tracking response. I'm also thinking I might start looking into classes... I imagine my script would be a lot better structured if I had a class for loading and parsing the XML, a class for making the images draggable etc. Do it. Sooner you get into classes the better. The timeline sucks, and is utterly wimpy in comparison to what you can pull off with structured OOP. And AS3 is the language to do it in. It's the most modern OOP language, so takes more standards into account than any other language.

fatbuoy1- 04-04-2008

you WILL need to create a new array during each <project> iteration for slideData Ok... so can I contain a variable within the array name? As in call the array slides(slideIndex) or something? At the moment the code is like this //Load list of example images trace("XML File Loaded"); var xmlData = new XML(evt.target.data); // specify a node name to read as a list var projectList:XMLList = xmlData.project; // Iterate through the list of image nodes for each (var projectNode:XML in projectList) { // extract each node's data var t:String = projectNode.title; var d:String = projectNode.description; //HERES THE BIT IM HAVING TROUBLE WITH var slidesList:XMLList = projectNode.slides; for each (var slidesNode:XML in slidesList) { var u:String = slidesNode.url; var st:String = slidesNode.title; var c:String = slidesNode.caption; slidesData.push({url:u, title:st, caption:c}); trace (slidesData[0].url); } // Add data elements as a new Flash object in array portfolioData.push({title:t, description:d, slides:slidesData}); trace (portfolioData[0].slides); } Theres two trace statements in there... trace (slidesData[0].url); returns blank and trace (portfolioData[0].slides); returns , ,, So I THINK that means the 'slides' array is being added to the portfolioData array ok for each project... but its just adding an array with two blank values. Here's some food for thought for you Eerie... thats exactly the way Im trying to do it... I just couldnt find how to limit the amount of objects in an array?
bigmac- 04-04-2008

No... the slides array is being filled up with slides from all projects, then being added to each project. When you don't flush the array between project cycles, then the second project will still have data in it from the first project, and the thrid project will still have data from the first AND second projects, etc... So, like I say, flush the array between project cycles... //HERES THE BIT IM HAVING TROUBLE WITH var slidesList:XMLList = projectNode.slides; var slidesData:Array = new Array(); for each (var slidesNode:XML in slidesList) { var u:String = slidesNode.url; var st:String = slidesNode.title; var c:String = slidesNode.caption; slidesData.push({url:u, title:st, caption:c}); trace (slidesData[0].url); } As for limiting the number of items in an array... you just have to remove one item each time you add a new item. So, do this... // create a "DEQ" or "double-ended queue". // this is a new array with five positions (in this example: 5 zeros). var _deq:Array = new Array(0, 0, 0, 0, 0); // STACK: add a new item to the front of the array function stack(val):void { _deq.unshift(val); _deq.pop(); } // QUEUE: add a new item to the back of the array function queue(val):void { _deq.push(val); _deq.shift(); }

fatbuoy1- 04-04-2008

Thanks, have FINALLY managed to get that array thing sorted out! it didnt help that I was referencing the 'slides' nodes instead of the 'slide' node. This things starting to com together nicely :D Is it possible, if I import a Flash .swf instead of an image, for the imported flash to display information contained in an array in the original flash file?

bigmac- 04-04-2008

Sure is... You've always been able to do data sharing in some capacity by accessing properties of a parent object in AS2. However, its substantially more powerful now with the new DOM model in AS3. You can now do class sharing, which is the cornerstone of run-time library sharing. It also makes patterns like the singleton (basic OOP design) way more useful since all loaded SWFs can tap into the central data architecture. So yes, the short answer is that you CAN use data loaded by the parent within imported child movies. If ever you were interested in getting into classes, now would be the time since it would make life infinantly easier for managing data between movies. If you want to go down that road, start reading... get a sense of what a class IS and figure out the difference between static and instance members. Then we could proceed on that topic.

fatbuoy1- 04-04-2008

Ok thanks, i'll take a look at those things. Oh and i've been meaning to ask you, should I be being pernickety about deleting event listeners if I don't need them? Like only having event listeners on the menu buttons when the menu is actually open, that kind of thing? Or does it not make much difference to memory?

fatbuoy1- 04-04-2008

hmm... do I need to start going into custom classes if I just want to get the imported child movie to display text contained in an array from the parent movie? I've tried putting caption_txt.text = stage.portfolioData[projectIndex].slides[slideIndex].caption; in the child's timeline but it can't read see the array when its imported. Also, i've created a function called clearStage to make all the slides exit right and clear the stage, but when I try to call it it says 'TypeError: Error #1010: A term is undefined and has no properties.' Can you see any problems? function clearStage():void { var currentX:Number = main.photo_mc.x; var rightEdge:Number = stage.stageWidth; var exitRight:Tween = new Tween(main.photo_mc, "x", Regular.easeIn, currentX, rightEdge+400, 1, true); var timer:Timer = new Timer(1000,1); timer.addEventListener(TimerEvent.TIMER_COMPLETE, deletePhotos); function deletePhotos(evt:TimerEvent) { removeChild(main.photo_mc); } } clearStage();

Forumer™ is Voted #1 Free Forum Hosting provider
Build your own community today with the largest message board hosting company.