[Flashcoders] This actionscript error is driving me mad
Hello. I am a newbie to this list, so I am sorry if this message is off-topic. If it is, I would be obliged if anyone could direct me to the correct place. I am a veteran programmer but I am new to actionscript. I have come across some strange behaviour which is driving me mad. Following is a part of my code : ...[snip]... private var pnt:Point = new Point(); private var dirp:int; private var fastp:int; private var i:int; private var pathB:Array; ...[snip]... for (dirp=fastp; dirp=i; dirp++) { // BUG!!! If I UNCOMMENT 1 of the 2 following lines, code gets mixed up. // pnt.x=pathB[dirp][0].x+pathB[dirp][2].x; // pnt.y=pathB[dirp][0].y+pathB[dirp][2].y; pnt=new Point(pathB[dirp][0].x+pathB[dirp][2].x,pathB[dirp][0].y+pathB[dirp][2].y); if (addElement(pnt, dirp, pathB[dirp][2], pathB[dirp][3]+1)) return pathF; } As I mention above, if I uncomment //pnt.x=... or //pnt.y=... or if I even replace them with something like pnt.x=pnt.x+1; then my code gets mixed up and returns wrong results. This is driving me nuts because these two lines shouldn't have any effect since right below them there is pnt=new Point(...); which supposedly cancels the 2 previous instructions. Right? Could anyone, please, show me the obvious that I can't see? Many thanks in advance, Bill Kotsias ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] A Flex 2 component in Flash CS3
Since the mx package cannot be accessed by the Flash CS3 compiler, as it belongs to the Flex SDK, you would have to encapsulate the Flex component functionality as a standalone SWF with maybe an API to allow communication with either your Flash or your Flex application. ___ Joseph Balderson, Flash Platform Developer | http://joeflash.ca Writing partner, Community MX | http://www.communitymx.com Abobe Certified Developer Trainer Patrick Mineault wrote: Hey everyone, I have to figure out a way to have a Flex 2 component work in both Flex 2 and in Flash CS3. Basically the component is a custom made Google maps type component entirely written in AS3 (no MXML at all). The component itself is pretty light, but it can have layers and tiles as children (no Flex UI components though). Thankfully, everything that can be attached as children to the component inherits Sprite, not mx.core.UIComponent. It's currently working swell as a Flex component, and now I have to figure out how to make it work in both Flex and Flash as painlessly as possible. The component extends mx.core.UIComponent and implements createChildren, updateDisplayList, saveState and loadState (implements IHistoryManagerClient). I was thinking maybe rewriting the component so it inherits Sprite instead and then create one dummy component for Flex and one for Flash, add an instance of the component in the dummy component, and forwarding the events between the real and dummy components (basically using composition). As I understand it, I have to inherit fl.core.UIComponent in Flash and NOT mx.core.UIComponent, so I don't see a way around composition. Also, I was wondering whether Flash would choke on the [Bindable] metatags sprinkled through the layers classes. If anybody has done this kind of work and has any hints on going forward, it would be highly appreciated. Patrick Mineault ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] This actionscript error is driving me mad
You're right, pnt = new (...) cancels it out. However, if, *somewhere* before the loop, you assign a point from pathB to pnt... pnt = pathB[n][n]; ...then the values of that same specific point instance will be changed (pnt is already assigned to a point), and as such, when you assign a new point to pnt, but using values from a point of pathB, the values would have changed. Remember that in actionscript, your objects are references: var p1:Point = new Point(10, 20); var p2:Point = p1; // not a copy, but a reference p2.x = 0; trave (p1.x); // traces 0, not 10 That's the only thing I can imagine. I guess it will depends on what's on the [snip] part of your code. Is anything (that's also part of the pathB array) assigned to pnt? Zeh Bill Kotsias wrote: Hello. I am a newbie to this list, so I am sorry if this message is off-topic. If it is, I would be obliged if anyone could direct me to the correct place. I am a veteran programmer but I am new to actionscript. I have come across some strange behaviour which is driving me mad. Following is a part of my code : ...[snip]... private var pnt:Point = new Point(); private var dirp:int; private var fastp:int; private var i:int; private var pathB:Array; ...[snip]... for (dirp=fastp; dirp=i; dirp++) { // BUG!!! If I UNCOMMENT 1 of the 2 following lines, code gets mixed up. // pnt.x=pathB[dirp][0].x+pathB[dirp][2].x; // pnt.y=pathB[dirp][0].y+pathB[dirp][2].y; pnt=new Point(pathB[dirp][0].x+pathB[dirp][2].x,pathB[dirp][0].y+pathB[dirp][2].y); if (addElement(pnt, dirp, pathB[dirp][2], pathB[dirp][3]+1)) return pathF; } As I mention above, if I uncomment //pnt.x=... or //pnt.y=... or if I even replace them with something like pnt.x=pnt.x+1; then my code gets mixed up and returns wrong results. This is driving me nuts because these two lines shouldn't have any effect since right below them there is pnt=new Point(...); which supposedly cancels the 2 previous instructions. Right? Could anyone, please, show me the obvious that I can't see? Many thanks in advance, Bill Kotsias ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders