RE: [Flashcoders] AS3 - Problem with first item in Array
Personally, I'm of the opinion that any time you have hard coded information in a class, you should often avoid doing so and put it in an external source (like an XML config file), but if it's a minor thing to have it in the class (which it often is, you don't need to take the time to make everything dynamic, though in a perfect world, you would), then you don't have to, but it should/could (again, in a more perfect world) be a constant. So: package { class MyClass { public static const MYVAR_DEFAULT:Number = 10; private var _myVar:Number; public function MyClass() { _myVar = MyClass.MYVAR_DEFAULT; } private function resetValues():void { _myVar = MyClass.MYVAR_DEFAULT } } } You can change the value of _myVar as much as you want later, but you have the inital value as a constant, which you can use to reset _myVar if need be (like in the resetValues method above), or for other classes to pull. It doesn't have to be this way, I just think it's a good way to handle hard coded values in a class sometimes. Jason Merrill Bank of America Enterprise Technology & Global Risk L&LD Instructional Technology & Media Join the Bank of America Flash Platform Developer Community Are you a Bank of America associate interested in innovative learning ideas and technologies? Check out our internal GT&O Innovative Learning Blog & subscribe. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] AS3 - Problem with first item in Array
SJM, The tweener is undefined on jpg 1-4. The fifth is alright. Over tweener =[object MovieClip] Out tweener =[object MovieClip] Over tweener =undefined TypeError: Error #1009: Cannot access a property or method of a null object reference. at fl.transitions::Tween/setPosition() at fl.transitions::Tween/set position() at fl.transitions::Tween() at MainClass/mOver() Out tweener =undefined TypeError: Error #1009: Cannot access a property or method of a null object reference. at fl.transitions::Tween/setPosition() at fl.transitions::Tween/set position() at fl.transitions::Tween() at MainClass/mOut() ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Re: [Flashcoders] AS3 - Problem with first item in Array
Kerry Thompson wrote: Jim McIntyre wrote: I got the impression from the AS2 documentation that one *should* set an initial value for a variable in the class body, as long as the initial value could be defined at compile time. However, I've seen many folks leave the value undefined by not assigning anything in the class body, like your example below. What's the real deal? Is there a reason it's better (or worse) to favor one practice over the other? I'm not sure what you mean by "class body", but in the example you cited, the variable is initialized in the constructor. That guarantees that the variable will be initialized. As for initializing it in the variable declaration vs. in the constructor, it's purely a matter of style and circumstance. Sometimes you can't initialize a variable until the class is constructed--for example, a path. It's crucial to initialize your variables--uninitialized variables are the source of more bugs than any other single thing I can think of. It doesn't matter a lot where you initialize the variables, though. Sorry for my sloppy terminology! By saying "class body" I meant initializing it here, which is what the documentation recommends: class myClass { public var myVar:Number = 10; } as opposed to here: class myClass { public var myVar:Number; public function myClass() { this.myVar = 10; } } Thanks for the input, though. The documentation I cited is in the section dealing with coding practices and style, after all, so I guess there's no real technical reason to do it one way or the other... as long as it's done. -Jim ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] AS3 - Problem with first item in Array
I notice the use of the ev.target.name. You set it to number and lateron you the name. You don't have to give it a name, because Flash does this for you. If you use ev.target it gives you the correct instance name. I am now struggling with your tween. The last image works OK, but 1 - 4 not. Work in progress Cor -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of SJM - Flash Sent: donderdag 17 juli 2008 20:20 To: Flash Coders List Subject: Re: [Flashcoders] AS3 - Problem with first item in Array Hey Cor This is a continuation from the thing you were looking on Sunday for me! I took your advice and re-wrote most of the code! You will notice first time round it will trace all the correct info (5 image URLs) for the array but when you get to... trace("LOAD COMPLETE - "+ev.target.content.name); It will only trace out 4 objects! --- DynamicImage package { import flash.display.MovieClip; import flash.display.Loader; import flash.net.URLRequest; import flash.events.Event; public class DynamicImage extends MovieClip { private var _file:String; public function set file (filename:String):void { // This is the function to set the file name this._file = filename; loadImage(); // // Start of Class // } public function DynamicImage() { } private function loadImage():void { var imageLoader:Loader = new Loader(); // Set loader try { var imageURL:URLRequest = new URLRequest(this._file); // Set file name imageLoader.load (imageURL); imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete); trace("DI URL - "+this._file); } catch (err:Error) { trace("No files are loading - "+err); } } private function loadComplete(ev:Event):void { // Load image dynamicly trace("Image Being loaded"); this.addChild(ev.target.content); trace("LOAD COMPLETE - "+ev.target.content.name); } } } - Original Message - From: Cor To: 'Flash Coders List' Sent: Thursday, July 17, 2008 7:07 PM Subject: RE: [Flashcoders] AS3 - Problem with first item in Array What does your class DynamicImage look like? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of SJM - Flash Sent: donderdag 17 juli 2008 19:08 To: Flash Coders List Subject: [Flashcoders] AS3 - Problem with first item in Array Hi Guys im having a bit of a nightmare with the first item in an array! For some reason when the flash file is first loaded it will not display any information related to the first item in the array! When the flash its reloaded it works fine! Any ideas? SJM - My code... package { import flash.events.*; import flash.display.MovieClip; import flash.display.DisplayObject; import flash.geom.Point; import fl.transitions.Tween; import fl.transitions.easing.*; import flash.filters.GlowFilter; import flash.net.URLRequest; import flash.net.navigateToURL; import flash.display.StageScaleMode; public class mainClass extends MovieClip { // // Vars and Arrays // public var imageHolder:MovieClip; public var containerX:Number = (stage.stageWidth / 5); public var imgArray:Array = new Array("uploads/images/dev_xantium.jpg", "uploads/images/dev_the-limes.jpg", "uploads/images/dev_richmond-grove.jpg", "uploads/images/dev_bridgewater-gardens.jpg", "uploads/images/dev_gransmoor-gardens.jpg"); public var linkArray:Array = new Array("xantium", "the-limes", "57-richmond-grove", "bridgewater-gardens", "gransmoor-gardens"); public var titleArray:Array = new Array("Xantium", "The Limes", "57 Richmond Grove", "Bridgewater Gardens", "Gransmoor Gardens"); public var mycontainer:Array = new Array(); public var imageMask:Array = new Array(); // // Start of mainClass // public function mainClass():void { for (var i:int = 0; i < 5; i++) { create_MCs(i, containerX, imgArray[i]); containerX += (stage.stageWidth / 5) - 46;
RE: [Flashcoders] AS3 - Problem with first item in Array
OK, I did some adjustment and it work OK here. The only error is referring to the php file wich I don't have ofcourse. Please tell me if it helped you. package { import flash.events.*; import flash.display.MovieClip; import flash.display.DisplayObject; import flash.geom.Point; import fl.transitions.Tween; import fl.transitions.easing.*; import flash.filters.GlowFilter; import flash.net.URLRequest; import flash.net.navigateToURL; import flash.display.StageScaleMode; public class MainClass extends MovieClip { // // Vars and Arrays // public var imageHolder:MovieClip; public var containerX:Number; public var imgArray:Array ; public var linkArray:Array ; public var titleArray:Array; public var mycontainer:Array ; public var imageMask:Array ; // // Start of MainClass // public function MainClass():void { RECOPY THE CORRECT PICTURES HERE imgArray = new Array("uploads/images/dev_xantium.jpg", "uploads/images/dev_the-limes.jpg", "uploads/images/dev_richmond-grove.jpg", "uploads/images/dev_bridgewater-gardens.jpg", "uploads/images/dev_gransmoor-gardens.jpg"); linkArray = new Array("xantium", "the-limes", "57-richmond-grove", "bridgewater-gardens", "gransmoor-gardens"); titleArray = new Array("Xantium", "The Limes", "57 Richmond Grove", "Bridgewater Gardens", "Gransmoor Gardens"); containerX = (stage.stageWidth / 5); for (var i:int = 0; i < 5; i++) { create_MCs(i, containerX, imgArray[i]); containerX += (stage.stageWidth / 5) - 46; } } // // Create MCs // public function create_MCs(number:int, x:int, imgURL:String) { trace(imgURL); // Create Container MC mycontainer = new Array(); mycontainer[number] = new MovieClip(); addChild(mycontainer[number]); // Create new DynamicImage MC to hold loaded image imageHolder = new DynamicImage(); imageHolder.file = imgURL; mycontainer[number].addChild(imageHolder); // Create mask MC and set mask to loaded image imageMask = new Array(); imageMask[number] = new MovieClip(); imageMask[number].graphics.beginFill(0xFF); imageMask[number].graphics.drawRect(-40, 0, 80, 200); imageMask[number].graphics.endFill(); mycontainer[number].addChild(imageMask[number]); // Set mask to loaded image imageHolder.mask = imageMask[number]; // Set name for loaded image mycontainer[number].name = number; // Add listeners and button info mycontainer[number].addEventListener(MouseEvent.MOUSE_OVER, mOver); mycontainer[number].addEventListener(MouseEvent.MOUSE_OUT, mOut); mycontainer[number].addEventListener(MouseEvent.CLICK, mClick); mycontainer[number].mouseChildren = false; mycontainer[number].buttonMode = true; // Set new X/Y for main container mycontainer[number].y = 40; mycontainer[number].x = x; // Set new X/Y for DynamicImage (containing image) imageHolder.x = - 100; imageHolder.y = 0; // Set new X/Y for image mask imageMask[number].y = 0; // Apply outer glow to containers var outerGlow:GlowFilter = new GlowFilter(0x00, // color:uint,
RE: [Flashcoders] AS3 - Problem with first item in Array
Jim McIntyre wrote: > I got the impression from the AS2 documentation that one *should* set an > initial value for a variable in the class body, as long as the initial > value could be defined at compile time. > > However, I've seen many folks leave the value undefined by not assigning > anything in the class body, like your example below. > > What's the real deal? Is there a reason it's better (or worse) to favor > one practice over the other? I'm not sure what you mean by "class body", but in the example you cited, the variable is initialized in the constructor. That guarantees that the variable will be initialized. As for initializing it in the variable declaration vs. in the constructor, it's purely a matter of style and circumstance. Sometimes you can't initialize a variable until the class is constructed--for example, a path. It's crucial to initialize your variables--uninitialized variables are the source of more bugs than any other single thing I can think of. It doesn't matter a lot where you initialize the variables, though. Cordially, Kerry Thompson ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] AS3 - Problem with first item in Array
I will dive into it some deeper. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of SJM - Flash Sent: donderdag 17 juli 2008 20:20 To: Flash Coders List Subject: Re: [Flashcoders] AS3 - Problem with first item in Array Hey Cor This is a continuation from the thing you were looking on Sunday for me! I took your advice and re-wrote most of the code! You will notice first time round it will trace all the correct info (5 image URLs) for the array but when you get to... trace("LOAD COMPLETE - "+ev.target.content.name); It will only trace out 4 objects! --- DynamicImage package { import flash.display.MovieClip; import flash.display.Loader; import flash.net.URLRequest; import flash.events.Event; public class DynamicImage extends MovieClip { private var _file:String; public function set file (filename:String):void { // This is the function to set the file name this._file = filename; loadImage(); // // Start of Class // } public function DynamicImage() { } private function loadImage():void { var imageLoader:Loader = new Loader(); // Set loader try { var imageURL:URLRequest = new URLRequest(this._file); // Set file name imageLoader.load (imageURL); imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete); trace("DI URL - "+this._file); } catch (err:Error) { trace("No files are loading - "+err); } } private function loadComplete(ev:Event):void { // Load image dynamicly trace("Image Being loaded"); this.addChild(ev.target.content); trace("LOAD COMPLETE - "+ev.target.content.name); } } } - Original Message - From: Cor To: 'Flash Coders List' Sent: Thursday, July 17, 2008 7:07 PM Subject: RE: [Flashcoders] AS3 - Problem with first item in Array What does your class DynamicImage look like? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of SJM - Flash Sent: donderdag 17 juli 2008 19:08 To: Flash Coders List Subject: [Flashcoders] AS3 - Problem with first item in Array Hi Guys im having a bit of a nightmare with the first item in an array! For some reason when the flash file is first loaded it will not display any information related to the first item in the array! When the flash its reloaded it works fine! Any ideas? SJM - My code... package { import flash.events.*; import flash.display.MovieClip; import flash.display.DisplayObject; import flash.geom.Point; import fl.transitions.Tween; import fl.transitions.easing.*; import flash.filters.GlowFilter; import flash.net.URLRequest; import flash.net.navigateToURL; import flash.display.StageScaleMode; public class mainClass extends MovieClip { // // Vars and Arrays // public var imageHolder:MovieClip; public var containerX:Number = (stage.stageWidth / 5); public var imgArray:Array = new Array("uploads/images/dev_xantium.jpg", "uploads/images/dev_the-limes.jpg", "uploads/images/dev_richmond-grove.jpg", "uploads/images/dev_bridgewater-gardens.jpg", "uploads/images/dev_gransmoor-gardens.jpg"); public var linkArray:Array = new Array("xantium", "the-limes", "57-richmond-grove", "bridgewater-gardens", "gransmoor-gardens"); public var titleArray:Array = new Array("Xantium", "The Limes", "57 Richmond Grove", "Bridgewater Gardens", "Gransmoor Gardens"); public var mycontainer:Array = new Array(); public var imageMask:Array = new Array(); // // Start of mainClass // public function mainClass():void { for (var i:int = 0; i < 5; i++) { create_MCs(i, containerX, imgArray[i]); containerX += (stage.stageWidth / 5) - 46; } } // // Create MCs // public function create_MCs(number:int, x:int, imgURL:String) { trace(imgURL); // Create Container M
Re: [Flashcoders] AS3 - Problem with first item in Array
What's the real deal? Is there a reason it's better (or worse) to favor one practice over the other? Im new to AS3 so still learning from what ive been told you declare a static var here and any you want to update in the class body! - Original Message - From: Jim McIntyre To: Flash Coders List Sent: Thursday, July 17, 2008 7:11 PM Subject: Re: [Flashcoders] AS3 - Problem with first item in Array I got the impression from the AS2 documentation that one *should* set an initial value for a variable in the class body, as long as the initial value could be defined at compile time. http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=1116.html However, I've seen many folks leave the value undefined by not assigning anything in the class body, like your example below. What's the real deal? Is there a reason it's better (or worse) to favor one practice over the other? -Jim jonathan howe wrote: > Hi, SJM, > > Hypothesis: Don't know if this is different for AS3 (couldn't find the > appropriate documentation in a quick search) but I got into the habit of > avoiding assigning values for declared variables in the class body unless > they are static variables. My recommendation would be declare variables like > your arrays in the class body: > > public var containerX:Number; > > And then initialize them in your mainClass() function > > containerX = (stage.stageWidth / 5); > > Otherwise you may get unpredictable results based on what's in memory at the > time. > > ___ 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] AS3 - Problem with first item in Array
Hey Cor This is a continuation from the thing you were looking on Sunday for me! I took your advice and re-wrote most of the code! You will notice first time round it will trace all the correct info (5 image URLs) for the array but when you get to... trace("LOAD COMPLETE - "+ev.target.content.name); It will only trace out 4 objects! --- DynamicImage package { import flash.display.MovieClip; import flash.display.Loader; import flash.net.URLRequest; import flash.events.Event; public class DynamicImage extends MovieClip { private var _file:String; public function set file (filename:String):void { // This is the function to set the file name this._file = filename; loadImage(); // // Start of Class // } public function DynamicImage() { } private function loadImage():void { var imageLoader:Loader = new Loader(); // Set loader try { var imageURL:URLRequest = new URLRequest(this._file); // Set file name imageLoader.load (imageURL); imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete); trace("DI URL - "+this._file); } catch (err:Error) { trace("No files are loading - "+err); } } private function loadComplete(ev:Event):void { // Load image dynamicly trace("Image Being loaded"); this.addChild(ev.target.content); trace("LOAD COMPLETE - "+ev.target.content.name); } } } - Original Message - From: Cor To: 'Flash Coders List' Sent: Thursday, July 17, 2008 7:07 PM Subject: RE: [Flashcoders] AS3 - Problem with first item in Array What does your class DynamicImage look like? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of SJM - Flash Sent: donderdag 17 juli 2008 19:08 To: Flash Coders List Subject: [Flashcoders] AS3 - Problem with first item in Array Hi Guys im having a bit of a nightmare with the first item in an array! For some reason when the flash file is first loaded it will not display any information related to the first item in the array! When the flash its reloaded it works fine! Any ideas? SJM - My code... package { import flash.events.*; import flash.display.MovieClip; import flash.display.DisplayObject; import flash.geom.Point; import fl.transitions.Tween; import fl.transitions.easing.*; import flash.filters.GlowFilter; import flash.net.URLRequest; import flash.net.navigateToURL; import flash.display.StageScaleMode; public class mainClass extends MovieClip { // // Vars and Arrays // public var imageHolder:MovieClip; public var containerX:Number = (stage.stageWidth / 5); public var imgArray:Array = new Array("uploads/images/dev_xantium.jpg", "uploads/images/dev_the-limes.jpg", "uploads/images/dev_richmond-grove.jpg", "uploads/images/dev_bridgewater-gardens.jpg", "uploads/images/dev_gransmoor-gardens.jpg"); public var linkArray:Array = new Array("xantium", "the-limes", "57-richmond-grove", "bridgewater-gardens", "gransmoor-gardens"); public var titleArray:Array = new Array("Xantium", "The Limes", "57 Richmond Grove", "Bridgewater Gardens", "Gransmoor Gardens"); public var mycontainer:Array = new Array(); public var imageMask:Array = new Array(); // // Start of mainClass // public function mainClass():void { for (var i:int = 0; i < 5; i++) { create_MCs(i, containerX, imgArray[i]); containerX += (stage.stageWidth / 5) - 46; } } // // Create MCs // public function create_MCs(number:int, x:int, imgURL:String) { trace(imgURL); // Create Container MC mycontainer[number] = new MovieClip(); addChild(mycontainer[number]); // Create new DynamicImage MC to hold loaded image imageHolder = new DynamicImage(); imageHolder.file = imgURL; mycontainer[number].addChild(imageHolde
RE: [Flashcoders] AS3 - Problem with first item in Array
I took the liberty to do it on your code: package { import flash.events.*; import flash.display.MovieClip; import flash.display.DisplayObject; import flash.geom.Point; import fl.transitions.Tween; import fl.transitions.easing.*; import flash.filters.GlowFilter; import flash.net.URLRequest; import flash.net.navigateToURL; import flash.display.StageScaleMode; public class MainClass extends MovieClip { // // Vars and Arrays // public var imageHolder:MovieClip; public var containerX:Number; public var imgArray:Array ; public var linkArray:Array ; public var titleArray:Array; public var mycontainer:Array ; public var imageMask:Array ; // // Start of MainClass // public function MainClass():void { imgArray = new Array("uploads/images/dev_xantium.jpg", "uploads/images/dev_the-limes.jpg", "uploads/images/dev_richmond-grove.jpg", "uploads/images/dev_bridgewater-gardens.jpg", "uploads/images/dev_gransmoor-gardens.jpg"); linkArray = new Array("xantium", "the-limes", "57-richmond-grove", "bridgewater-gardens", "gransmoor-gardens"); titleArray = new Array("Xantium", "The Limes", "57 Richmond Grove", "Bridgewater Gardens", "Gransmoor Gardens"); containerX = (stage.stageWidth / 5); for (var i:int = 0; i < 5; i++) { create_MCs(i, containerX, imgArray[i]); containerX += (stage.stageWidth / 5) - 46; } } // // Create MCs // public function create_MCs(number:int, x:int, imgURL:String) { trace(imgURL); // Create Container MC mycontainer = new Array(); mycontainer[number] = new MovieClip(); addChild(mycontainer[number]); // Create new DynamicImage MC to hold loaded image imageHolder = new DynamicImage(); imageHolder.file = imgURL; mycontainer[number].addChild(imageHolder); // Create mask MC and set mask to loaded image imageMask = new Array(); imageMask[number] = new MovieClip(); imageMask[number].graphics.beginFill(0xFF); imageMask[number].graphics.drawRect(-40, 0, 80, 200); imageMask[number].graphics.endFill(); mycontainer[number].addChild(imageMask[number]); // Set mask to loaded image imageHolder.mask = imageMask[number]; // Set name for loaded image mycontainer[number].name = number; // Add listeners and button info mycontainer[number].addEventListener(MouseEvent.MOUSE_OVER, mOver); mycontainer[number].addEventListener(MouseEvent.MOUSE_OUT, mOut); mycontainer[number].addEventListener(MouseEvent.CLICK, mClick); mycontainer[number].mouseChildren = false; mycontainer[number].buttonMode = true; // Set new X/Y for main container mycontainer[number].y = 40; mycontainer[number].x = x; // Set new X/Y for DynamicImage (containing image) imageHolder.x = - 100; imageHolder.y = 0; // Set new X/Y for image mask imageMask[number].y = 0; // Apply outer glow to containers var outerGlow:GlowFilter = new GlowFilter(0x00, // color:uint, 1,// alpha:Number 11.0, // blurX:Number
RE: [Flashcoders] AS3 - Problem with first item in Array
It is a proper thing to declare your variables at the top of your class ans import the according classes. And instanciate the variabele at the location it is needed. This keeps memory use minimized and scope guaranteed. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jim McIntyre Sent: donderdag 17 juli 2008 20:11 To: Flash Coders List Subject: Re: [Flashcoders] AS3 - Problem with first item in Array I got the impression from the AS2 documentation that one *should* set an initial value for a variable in the class body, as long as the initial value could be defined at compile time. http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.h tm?context=LiveDocs_Parts&file=1116.html However, I've seen many folks leave the value undefined by not assigning anything in the class body, like your example below. What's the real deal? Is there a reason it's better (or worse) to favor one practice over the other? -Jim jonathan howe wrote: > Hi, SJM, > > Hypothesis: Don't know if this is different for AS3 (couldn't find the > appropriate documentation in a quick search) but I got into the habit of > avoiding assigning values for declared variables in the class body unless > they are static variables. My recommendation would be declare variables like > your arrays in the class body: > > public var containerX:Number; > > And then initialize them in your mainClass() function > > containerX = (stage.stageWidth / 5); > > Otherwise you may get unpredictable results based on what's in memory at the > time. > > ___ 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] AS3 - Problem with first item in Array
Thanks for the advice! - Original Message - From: jonathan howe To: Flash Coders List Sent: Thursday, July 17, 2008 6:31 PM Subject: Re: [Flashcoders] AS3 - Problem with first item in Array Hi, SJM, Hypothesis: Don't know if this is different for AS3 (couldn't find the appropriate documentation in a quick search) but I got into the habit of avoiding assigning values for declared variables in the class body unless they are static variables. My recommendation would be declare variables like your arrays in the class body: public var containerX:Number; And then initialize them in your mainClass() function containerX = (stage.stageWidth / 5); Otherwise you may get unpredictable results based on what's in memory at the time. -jonathan On Thu, Jul 17, 2008 at 7:08 PM, SJM - Flash <[EMAIL PROTECTED]> wrote: > Hi Guys im having a bit of a nightmare with the first item in an array! > > For some reason when the flash file is first loaded it will not display any > information related to the first item in the array! When the flash its > reloaded it works fine! > > Any ideas? > > SJM > > - > > My code... > > package { > > import flash.events.*; > import flash.display.MovieClip; > import flash.display.DisplayObject; > import flash.geom.Point; > import fl.transitions.Tween; > import fl.transitions.easing.*; > import flash.filters.GlowFilter; > import flash.net.URLRequest; > import flash.net.navigateToURL; > import flash.display.StageScaleMode; > > public class mainClass extends MovieClip > { > // > // Vars and Arrays > // > public var imageHolder:MovieClip; > public var containerX:Number = (stage.stageWidth / 5); > public var imgArray:Array = new Array("uploads/images/dev_xantium.jpg", > "uploads/images/dev_the-limes.jpg", > "uploads/images/dev_richmond-grove.jpg", > "uploads/images/dev_bridgewater-gardens.jpg", > "uploads/images/dev_gransmoor-gardens.jpg"); > public var linkArray:Array = new Array("xantium", > "the-limes", > "57-richmond-grove", > "bridgewater-gardens", > "gransmoor-gardens"); > public var titleArray:Array = new Array("Xantium", > "The Limes", > "57 Richmond Grove", > "Bridgewater Gardens", > "Gransmoor Gardens"); > public var mycontainer:Array = new Array(); > public var imageMask:Array = new Array(); > > // > // Start of mainClass > // > > public function mainClass():void > { > for (var i:int = 0; i < 5; i++) > { >create_MCs(i, containerX, imgArray[i]); >containerX += (stage.stageWidth / 5) - 46; > } > } > > // > // Create MCs > // > public function create_MCs(number:int, x:int, imgURL:String) > { > trace(imgURL); > > // Create Container MC > mycontainer[number] = new MovieClip(); > addChild(mycontainer[number]); > > // Create new DynamicImage MC to hold loaded image > imageHolder = new DynamicImage(); > imageHolder.file = imgURL; > mycontainer[number].addChild(imageHolder); > > // Create mask MC and set mask to loaded image > imageMask[number] = new MovieClip(); > imageMask[number].graphics.beginFill(0xFF); > imageMask[number].graphics.drawRect(-40, 0, 80, 200); > imageMask[number].graphics.endFill(); > mycontainer[number].addChild(imageMask[number]); > > // Set mask to loaded image > imageHolder.mask = imageMask[number]; > > // Set name for loaded image > mycontainer[number].name = number; > > // Add listeners and button info > mycontainer[number].addEventListener(MouseEvent.MOUSE_OVER, mOver); > mycontainer[number].addEventListener(MouseEvent.MOUSE_OUT, mOut); > mycontainer[number].addEventListener(MouseEvent.CLICK, mClick); > mycontainer[number].mouseChildren = false; > mycontainer[number].buttonMode = true; &
Re: [Flashcoders] AS3 - Problem with first item in Array
I got the impression from the AS2 documentation that one *should* set an initial value for a variable in the class body, as long as the initial value could be defined at compile time. http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=1116.html However, I've seen many folks leave the value undefined by not assigning anything in the class body, like your example below. What's the real deal? Is there a reason it's better (or worse) to favor one practice over the other? -Jim jonathan howe wrote: Hi, SJM, Hypothesis: Don't know if this is different for AS3 (couldn't find the appropriate documentation in a quick search) but I got into the habit of avoiding assigning values for declared variables in the class body unless they are static variables. My recommendation would be declare variables like your arrays in the class body: public var containerX:Number; And then initialize them in your mainClass() function containerX = (stage.stageWidth / 5); Otherwise you may get unpredictable results based on what's in memory at the time. ___ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
RE: [Flashcoders] AS3 - Problem with first item in Array
What does your class DynamicImage look like? -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of SJM - Flash Sent: donderdag 17 juli 2008 19:08 To: Flash Coders List Subject: [Flashcoders] AS3 - Problem with first item in Array Hi Guys im having a bit of a nightmare with the first item in an array! For some reason when the flash file is first loaded it will not display any information related to the first item in the array! When the flash its reloaded it works fine! Any ideas? SJM - My code... package { import flash.events.*; import flash.display.MovieClip; import flash.display.DisplayObject; import flash.geom.Point; import fl.transitions.Tween; import fl.transitions.easing.*; import flash.filters.GlowFilter; import flash.net.URLRequest; import flash.net.navigateToURL; import flash.display.StageScaleMode; public class mainClass extends MovieClip { // // Vars and Arrays // public var imageHolder:MovieClip; public var containerX:Number = (stage.stageWidth / 5); public var imgArray:Array = new Array("uploads/images/dev_xantium.jpg", "uploads/images/dev_the-limes.jpg", "uploads/images/dev_richmond-grove.jpg", "uploads/images/dev_bridgewater-gardens.jpg", "uploads/images/dev_gransmoor-gardens.jpg"); public var linkArray:Array = new Array("xantium", "the-limes", "57-richmond-grove", "bridgewater-gardens", "gransmoor-gardens"); public var titleArray:Array = new Array("Xantium", "The Limes", "57 Richmond Grove", "Bridgewater Gardens", "Gransmoor Gardens"); public var mycontainer:Array = new Array(); public var imageMask:Array = new Array(); // // Start of mainClass // public function mainClass():void { for (var i:int = 0; i < 5; i++) { create_MCs(i, containerX, imgArray[i]); containerX += (stage.stageWidth / 5) - 46; } } // // Create MCs // public function create_MCs(number:int, x:int, imgURL:String) { trace(imgURL); // Create Container MC mycontainer[number] = new MovieClip(); addChild(mycontainer[number]); // Create new DynamicImage MC to hold loaded image imageHolder = new DynamicImage(); imageHolder.file = imgURL; mycontainer[number].addChild(imageHolder); // Create mask MC and set mask to loaded image imageMask[number] = new MovieClip(); imageMask[number].graphics.beginFill(0xFF); imageMask[number].graphics.drawRect(-40, 0, 80, 200); imageMask[number].graphics.endFill(); mycontainer[number].addChild(imageMask[number]); // Set mask to loaded image imageHolder.mask = imageMask[number]; // Set name for loaded image mycontainer[number].name = number; // Add listeners and button info mycontainer[number].addEventListener(MouseEvent.MOUSE_OVER, mOver); mycontainer[number].addEventListener(MouseEvent.MOUSE_OUT, mOut); mycontainer[number].addEventListener(MouseEvent.CLICK, mClick); mycontainer[number].mouseChildren = false; mycontainer[number].buttonMode = true; // Set new X/Y for main container mycontainer[number].y = 40; mycontainer[number].x = x; // Set new X/Y for DynamicImage (containing image) imageHolder.x = - 100; imageHolder.y = 0; // Set new X/Y for image mask imageMask[number].y = 0; // Apply outer glow to containers var outerGlow:GlowFilter = new GlowFilter(0x00, // color:uint, 1,// alpha:Number 11.0, // blurX:Number 11.0, // blurY:Number 0.34, // strength:Number 3, // quality:int false, // inner:Boolean false); // knockout:Boolean mycontainer[number].filters = new Array(outerGlow); } // // Over/Out & Click Mouse events // public function mOver(ev:MouseEvent):void { var tweener = imageMask[ev.target.name]; var overTween:Tween = new Tween (tweener,// obj:Object "width",// prop:String Elastic.easeOut, // func:Function 80, // begin:Number 200, // fin
Re: [Flashcoders] AS3 - Problem with first item in Array
Hi, SJM, Hypothesis: Don't know if this is different for AS3 (couldn't find the appropriate documentation in a quick search) but I got into the habit of avoiding assigning values for declared variables in the class body unless they are static variables. My recommendation would be declare variables like your arrays in the class body: public var containerX:Number; And then initialize them in your mainClass() function containerX = (stage.stageWidth / 5); Otherwise you may get unpredictable results based on what's in memory at the time. -jonathan On Thu, Jul 17, 2008 at 7:08 PM, SJM - Flash <[EMAIL PROTECTED]> wrote: > Hi Guys im having a bit of a nightmare with the first item in an array! > > For some reason when the flash file is first loaded it will not display any > information related to the first item in the array! When the flash its > reloaded it works fine! > > Any ideas? > > SJM > > - > > My code... > > package { > > import flash.events.*; > import flash.display.MovieClip; > import flash.display.DisplayObject; > import flash.geom.Point; > import fl.transitions.Tween; > import fl.transitions.easing.*; > import flash.filters.GlowFilter; > import flash.net.URLRequest; > import flash.net.navigateToURL; > import flash.display.StageScaleMode; > > public class mainClass extends MovieClip > { > // > // Vars and Arrays > // > public var imageHolder:MovieClip; > public var containerX:Number = (stage.stageWidth / 5); > public var imgArray:Array = new Array("uploads/images/dev_xantium.jpg", > "uploads/images/dev_the-limes.jpg", > "uploads/images/dev_richmond-grove.jpg", > "uploads/images/dev_bridgewater-gardens.jpg", > "uploads/images/dev_gransmoor-gardens.jpg"); > public var linkArray:Array = new Array("xantium", > "the-limes", > "57-richmond-grove", > "bridgewater-gardens", > "gransmoor-gardens"); > public var titleArray:Array = new Array("Xantium", > "The Limes", > "57 Richmond Grove", > "Bridgewater Gardens", > "Gransmoor Gardens"); > public var mycontainer:Array = new Array(); > public var imageMask:Array = new Array(); > > // > // Start of mainClass > // > > public function mainClass():void > { > for (var i:int = 0; i < 5; i++) > { >create_MCs(i, containerX, imgArray[i]); >containerX += (stage.stageWidth / 5) - 46; > } > } > > // > // Create MCs > // > public function create_MCs(number:int, x:int, imgURL:String) > { > trace(imgURL); > > // Create Container MC > mycontainer[number] = new MovieClip(); > addChild(mycontainer[number]); > > // Create new DynamicImage MC to hold loaded image > imageHolder = new DynamicImage(); > imageHolder.file = imgURL; > mycontainer[number].addChild(imageHolder); > > // Create mask MC and set mask to loaded image > imageMask[number] = new MovieClip(); > imageMask[number].graphics.beginFill(0xFF); > imageMask[number].graphics.drawRect(-40, 0, 80, 200); > imageMask[number].graphics.endFill(); > mycontainer[number].addChild(imageMask[number]); > > // Set mask to loaded image > imageHolder.mask = imageMask[number]; > > // Set name for loaded image > mycontainer[number].name = number; > > // Add listeners and button info > mycontainer[number].addEventListener(MouseEvent.MOUSE_OVER, mOver); > mycontainer[number].addEventListener(MouseEvent.MOUSE_OUT, mOut); > mycontainer[number].addEventListener(MouseEvent.CLICK, mClick); > mycontainer[number].mouseChildren = false; > mycontainer[number].buttonMode = true; > > // Set new X/Y for main container > mycontainer[number].y = 40; > mycontainer[number].x = x; > > // Set new X/Y for DynamicImage (containing image) > imageHolder.x = - 100; > imageHolder.y = 0; > > // Set new X/Y for image mask > imageMask[number].y = 0; > > // Apply outer glow to containers > var outerGlow:GlowFilter = new GlowFilter(0x00, // color:uint, > 1,// alpha:Number > 11.0, // blurX:Number > 11.0, // blurY:Number > 0.34, // strength:Number > 3, // quality:int > false, // inner:Boolean > false); // knockout:Boolean > > mycontainer[number].filters = new Array(outerGlow); > > } > > // > // Over/Out & Click Mouse events > // > public function mOver(ev:Mou
[Flashcoders] AS3 - Problem with first item in Array
Hi Guys im having a bit of a nightmare with the first item in an array! For some reason when the flash file is first loaded it will not display any information related to the first item in the array! When the flash its reloaded it works fine! Any ideas? SJM - My code... package { import flash.events.*; import flash.display.MovieClip; import flash.display.DisplayObject; import flash.geom.Point; import fl.transitions.Tween; import fl.transitions.easing.*; import flash.filters.GlowFilter; import flash.net.URLRequest; import flash.net.navigateToURL; import flash.display.StageScaleMode; public class mainClass extends MovieClip { // // Vars and Arrays // public var imageHolder:MovieClip; public var containerX:Number = (stage.stageWidth / 5); public var imgArray:Array = new Array("uploads/images/dev_xantium.jpg", "uploads/images/dev_the-limes.jpg", "uploads/images/dev_richmond-grove.jpg", "uploads/images/dev_bridgewater-gardens.jpg", "uploads/images/dev_gransmoor-gardens.jpg"); public var linkArray:Array = new Array("xantium", "the-limes", "57-richmond-grove", "bridgewater-gardens", "gransmoor-gardens"); public var titleArray:Array = new Array("Xantium", "The Limes", "57 Richmond Grove", "Bridgewater Gardens", "Gransmoor Gardens"); public var mycontainer:Array = new Array(); public var imageMask:Array = new Array(); // // Start of mainClass // public function mainClass():void { for (var i:int = 0; i < 5; i++) { create_MCs(i, containerX, imgArray[i]); containerX += (stage.stageWidth / 5) - 46; } } // // Create MCs // public function create_MCs(number:int, x:int, imgURL:String) { trace(imgURL); // Create Container MC mycontainer[number] = new MovieClip(); addChild(mycontainer[number]); // Create new DynamicImage MC to hold loaded image imageHolder = new DynamicImage(); imageHolder.file = imgURL; mycontainer[number].addChild(imageHolder); // Create mask MC and set mask to loaded image imageMask[number] = new MovieClip(); imageMask[number].graphics.beginFill(0xFF); imageMask[number].graphics.drawRect(-40, 0, 80, 200); imageMask[number].graphics.endFill(); mycontainer[number].addChild(imageMask[number]); // Set mask to loaded image imageHolder.mask = imageMask[number]; // Set name for loaded image mycontainer[number].name = number; // Add listeners and button info mycontainer[number].addEventListener(MouseEvent.MOUSE_OVER, mOver); mycontainer[number].addEventListener(MouseEvent.MOUSE_OUT, mOut); mycontainer[number].addEventListener(MouseEvent.CLICK, mClick); mycontainer[number].mouseChildren = false; mycontainer[number].buttonMode = true; // Set new X/Y for main container mycontainer[number].y = 40; mycontainer[number].x = x; // Set new X/Y for DynamicImage (containing image) imageHolder.x = - 100; imageHolder.y = 0; // Set new X/Y for image mask imageMask[number].y = 0; // Apply outer glow to containers var outerGlow:GlowFilter = new GlowFilter(0x00, // color:uint, 1,// alpha:Number 11.0, // blurX:Number 11.0, // blurY:Number 0.34, // strength:Number 3, // quality:int false, // inner:Boolean false); // knockout:Boolean mycontainer[number].filters = new Array(outerGlow); } // // Over/Out & Click Mouse events // public function mOver(ev:MouseEvent):void { var tweener = imageMask[ev.target.name]; var overTween:Tween = new Tween (tweener,// obj:Object "width",// prop:String Elastic.easeOut, // func:Function 80, // begin:Number 200, // finish:Number 2, // duration:Number true);// useSeconds:Boolean = false setChildIndex(mycontainer[ev.target.name], (numChildren - 1)); } public function mOut(ev:MouseEvent):void { var tweener = imageMask[ev.target.name]; var outTween:Tween = new Tween (tweener, "width", Elastic.easeOut, 200, 80, 2, true); } public function mClick ( ev:MouseEvent ):void { goGetURL("index.php?page="