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(0xFF0000); > 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(0x000000, // 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="+linkArray[ev.target.name],""); > } > > ////////////////////////////////////////////////////////////// > // Useful functions - goGetURL > ////////////////////////////////////////////////////////////// > > public function goGetURL(myurl:String,taarget:String):void > { > var url:String = myurl; > var request:URLRequest = new URLRequest(url); > try > { > navigateToURL(request, target); > } > catch (e:Error) > { > trace("Error occurred!"); > } > } > > } > > } > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > -- -jonathan howe :: 404.434.2321 :: 180 High St Apt 26 Portland, ME 04101 _______________________________________________ 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