Quirky AS3 browser resize Help Please!


-

I have been battling against this browser resize issue for what seems like monthes. After several variations, my code is more effective, less concise and still not stable. I am basically trying to make my bg resize to the full browser and my site movieclip to center. If the browser gets smaller than the site MC then the site MC should constrain to fit in the browser. What I have right now works like 98% of the time, but still screws up and makes the site tiny or too big sometimes. I was hoping that someone else has gone through this and may be able to comment or drop in some good code. As I said mine got uglier and uglier as time went. I kind of hate this code. If I didn't write it, I'd say the author was insane... which I kind of am.

anyhow, any help is mucho appreciated.

here's the code for a look.

Code: import gs.TweenLite; stage.align=StageAlign.TOP_LEFT; stage.scaleMode=StageScaleMode.NO_SCALE; var siteHeight:Number = 600; var siteWidth:Number = 850; var siteRealHeight:Number = 600; var siteRealWidth:Number = 850; var siteAspectRatio:Number = 850/600; var theFactor:Number; var stageOldHeight:Number = 600; var stageOldWidth:Number = 850; var resizetimer:Timer = new Timer(1500,3); resizetimer.addEventListener("timer", firstResizeHandler); init(); function init() { stage.addEventListener(Event.RESIZE, resizeHandler); TweenLite.to(site, 1, {scaleX:1, scaleY:1}); resizetimer.start(); } function firstResizeHandler(event:TimerEvent):void { position(); } function resizeHandler(event:Event):void { position(); } function position(){ bg.width = stage.stageWidth; bg.height = stage.stageHeight; if(stage.stageWidth < siteWidth) { siteResizeWidth(); } if(stage.stageWidth > stageOldWidth && stage.stageWidth < 850) { siteResizeWidth(); } if(stage.stageHeight < siteHeight) { siteResizeHeight(); } if(stage.stageHeight > stageOldHeight && stage.stageHeight < 600) { siteResizeHeight(); } var siteX:Number = (stage.stageWidth)/2 ; var siteY:Number = (stage.stageHeight)/2 ; TweenLite.to(this.site, 0.5, {x:siteX, y:siteY}); stageOldHeight = stage.stageHeight stageOldWidth = stage.stageWidth; } function siteResizeWidth(){ theFactor = stage.stageWidth/stageOldWidth; site.width = (site.width*theFactor); siteWidth = (siteWidth*theFactor); siteHeight = siteHeight*theFactor; site.height = site.height*theFactor; } function siteResizeHeight(){ theFactor = stage.stageHeight/stageOldHeight; site.height = (site.height*theFactor); siteHeight = (siteHeight*theFactor); siteWidth = siteWidth*theFactor; site.width = site.width*theFactor; }
Posted On: Thursday 25th of October 2012 11:05:48 PM Total Views:  66
View Complete with Replies

RELATED TOPICS OF Flash / ActionScript PROGRAMMING LANGUAGE




What is causing this quirky friggin problem?

, I have an animation that appears fine in my computer but when we look at it on other computers, parts of the animation 'vibrate'. Another word might be 'jiggle' around. Has anyone else seen this issue Sometimes I can see why some people hate Flash!
VIEWS ON THIS POST

76

Posted on:

Tuesday 11th September 2012
View Replies!

Trouble making a liquid layout using as3

Hi ; I am pretty new with AS3 . I am making a liquid layout in flash using as3, it worked pretty well with the following code, for the movie clips that are going to be on stage from the very beginning. stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; setStage(); stage.addEventListener(Event.RESIZE, stageResize); function setStage():void { var WIDTH:Number = stage.stageWidth; var HEIGHT:Number = stage.stageHeight; demon_mc.x = WIDTH/2 - 50 ; devil_mc.x = WIDTH/2 + 280; } But when I try to load a movie clip by clicking a button and using the ddEventListener , it dose load, but doesn't float here is the code that I think have some problem: demon_mc.addEventListener(MouseEvent.CLICK, getSlider); function getSlider(event:MouseEvent):void { var myMovieClip:MovieClip = new galleryBg_mc(); addChild(myMovieClip); stage.scaleMode = StageScaleMode.NO_SCALE; setStage(); stage.addEventListener(Event.RESIZE, stageResize); function setStage():void { var WIDTH:Number = stage.stageWidth; var HEIGHT:Number = stage.stageHeight; myMovieClip.x = WIDTH/2; myMovieClip.y =330; } } as you can see I have defined the variables Width adn Height inside the function as well and I am using WIDTH/2 to define the x position, Well it laods in the exact position but won't float as I minimize the stage Thankx a loooooooooooot
VIEWS ON THIS POST

213

Posted on:

Thursday 25th October 2012
View Replies!

Multiple buttons in as3

Hi , I'm trying but I can't work this out. I have a single movieclip named button, and I want to use a "for" to multiply that movieclip, that way I can have multiple buttons and edit them all in a single function. It would be something like this: var _button = new button; for(i=0; i
VIEWS ON THIS POST

239

Posted on:

Thursday 25th October 2012
View Replies!

as3 full screen gallery

Can anyone point me to a decent full screen flash gallery tutorial (perhaps xml) with thumbnails. Much appreciated. Phil
VIEWS ON THIS POST

272

Posted on:

Thursday 25th October 2012
View Replies!

xml slideshow as3 with thumbnails

I would like to look at some sources for a slideshow populated by xml data. There's plenty online but I can't find one that first populates a slider menu with thumbnails from which you can choose an individual picture to see enlarged at a different place on stage. Does anyone know links for these sources Thank you. Apologies if this is an annoying request, I've been looking online for some time and don't seem to get anywhere, I think I don't know the right terms for the search.
VIEWS ON THIS POST

241

Posted on:

Thursday 25th October 2012
View Replies!

Low Volume on as3

Hy , I use this function to start the music in my project function tocar() { soundFactory.addEventListener(Event.COMPLETE, completeHandler); soundFactory.addEventListener(IOErrorEvent.IO_ERRO R, ioErrorHandler); soundFactory.addEventListener(ProgressEvent.PROGRE SS, progressHandler); soundFactory.load(request); song = soundFactory.play(); } -------------------------------------------------------------------------- Now i wana low volume of the music. I thought it was something like song.volume = 90; but i was wrong :p Can u help me on this\t
VIEWS ON THIS POST

224

Posted on:

Thursday 25th October 2012
View Replies!

as3 reading and displaying a twitter feed?

So i've been handed a nice little project from my boss. He wants an interactive flash panel that will rotate through several twitter accounts. Anyone have an idea of where i should start. much
VIEWS ON THIS POST

253

Posted on:

Thursday 25th October 2012
View Replies!

website links in as3

This must have been done before and be really easy but I am a newbie so just keep coming up with compiler errors. I have built a website in flash cs4 using as3. I have set up the time line so that each different page on the website exists at a different position on the timeline. Sections have been labeled so that I can jump to that section upon button click. What happens is when the link to the page/section is clicked the timeline jumps to that section and plays an animation that animates the page onto the stage then stops.("in animation") When you click another link the page should animate off of the stage ("out animation")and the next one animates in. (I have set the time line up so that after each "in" animation there is a stop and after each "out" animation there is a stop.) This is where i'm having the problem. I have set up event listeners for the button clicks But i can only get them to either play the "out" animation then that stops, using this code: Code: home.addEventListener(MouseEvent.CLICK, clickSection); about.addEventListener(MouseEvent.CLICK, clickSection); contact.addEventListener(MouseEvent.CLICK, clickSection); function clickSection(evtObj:MouseEvent) { play(); } or jump to the next section using this code: Code: home.addEventListener(MouseEvent.CLICK, clickSection); about.addEventListener(MouseEvent.CLICK, clickSection); contact.addEventListener(MouseEvent.CLICK, clickSection); function clickSection(evtObj:MouseEvent) { gotoAndPlay(evtObj.target.name); } What i would like to know is how to add the two together so that when a button is clicked the information about what was clicked is added to a variable. The function plays the out animation then when that is complete checks the variable where the page clicked information is then jumps to that section on the timeline and plays it's "in" animation Sorry for the long explanation, but I thought more facts would be better than less Jamie
VIEWS ON THIS POST

243

Posted on:

Thursday 25th October 2012
View Replies!

Need as3 Blur Filter help

how i can initialize the Blur Filter value in as3 pls help
VIEWS ON THIS POST

268

Posted on:

Thursday 25th October 2012
View Replies!

Stacking as3 elements under FLA elements.

Hi. I made a .as Class where some graphical elements are spawned into the stage. However, the Flash (.fla) have some internal graphics that are supposed to be over the graphical elements spawned from the custom class. I tried to make another layer over the layer where the as3 Class is being called, but unfortunately it doesn't do anything, the graphic from the .as still appearing over the internal .fla graphics. How I can make sure the .FLA graphics are appearing over the .as3 graphics (Am I clear)
VIEWS ON THIS POST

211

Posted on:

Thursday 25th October 2012
View Replies!

Bring your big brain here... xml and as3...

Code: var library:XML=; library.book = ; library.book.@bookID = 124; library.book.(@bookID = 124).page.@pageNumber = 1; library.book.(@bookID = 124).page.@pageNumber = 2; library.book.(@bookID = 124).page.@pageNumber = 3; trace(library); // this traces: // // // // // I would like my book to have three pages... anyone with a big brain have some ideas Ps - trying to do it without a loop
VIEWS ON THIS POST

219

Posted on:

Thursday 25th October 2012
View Replies!

kaspersky doesn't like as3's url!

Kirupians! [Summary ] I don't know if anybody had already encountred this bug, but, it seems that kaspersky in IE6 doesn't like the opening of popup windows by flash's as3. ExternalInterface.call ("function setWMWindow() {window.open('" + url + "', '" + target + "', '" + features + "');}"); [SYMPTOMS ] i know that many browsers have isues with mouse events used in buttons to triger url opening, that's why i use MouseEvent.CLICK for caling the above code. [MORE INFORMATION ] when i disable kaspersky evrything works fine in all tested browsers; FF, IE.. Thanx for reading!
VIEWS ON THIS POST

252

Posted on:

Thursday 25th October 2012
View Replies!

as3 loader

hello, i just setup this loader i found on the net: Code: var l:Loader = new Loader(); l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop); l.contentLoaderInfo.addEventListener(Event.COMPLETE, done); l.load(new URLRequest("world.jpg")); function loop(e:ProgressEvent):void{ var perc:Number = e.bytesLoaded / e.bytesTotal; percent.text = Math.ceil(perc*100).toString(); } function done(e:Event):void{ removeChildAt(0); percent = null; addChild(l); } what i dont understand is that everytime i click the refresh page the loader shows up again(this time loading the image faster) but if the image is already in cache the loader should not show at all (), i would like to achieve a loader that loads the image and after dont come up again everytime.
VIEWS ON THIS POST

273

Posted on:

Thursday 25th October 2012
View Replies!

active inactive button state in pure as3 (no mc)

Hi all, I want to create a set of buttons based on loaded images from xml that onClick turn red or grow in size, whatever, Clicking another turns that button red and the old one back to default. Alsoo it will attach a animated movieclip onclick to the button and when pressing another button, it swifts to that button. Code: var tracktype:Array = new Array; var imgArray:Array = new Array; var links:int; var locx:Array = new Array; var locy:Array = new Array; var loc:Array = new Array; var lname:Array = new Array; function showXML(e:Event):void { XML.ignoreWhitespace = true; var sitemap:XML = new XML(e.target.data); links = sitemap.link.length(); var i:int = 0; for (i = 0; i < links; i++) { loc.push(sitemap.link.loc[i].text()); locx.push(sitemap.link.locx[i].text()); locy.push(sitemap.link.locy[i].text()); tracktype.push(sitemap.link.tracktype[i].text()); lname.push(sitemap.link.name[i].text()); if (mapEnabled) { var loader:Loader=new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, GenerateSpots); loader.load(new URLRequest("images/hotspots/"+ tracktype[i]+".png")); } } } } function GenerateSpots(event:Event):void { imgArray.push(event.currentTarget.loader); if(imgArray.length==links) { for(var n:int=0;n
VIEWS ON THIS POST

249

Posted on:

Thursday 25th October 2012
View Replies!

Setting up Eclipse for as3 development.

Hiya folks. This is may be a silly question, but bare with me. I am currently using flashdevelop for my "home" work, but to be honest having gotten used to the benefits of eclipse at work i am finding flashdevelop a bit lacking. Mainly the ability to use breakpoints and watch the flash step through process by process and keep track of variables and accessible properties. I basically want to replace flashdevelop with eclipse, (i am not using flex), and i'd like to keep the ability that flashdevelop has to integrate easily with the flash ide (for quick running of the app with ctrl enter, and also for easy integration of the flash ide's library). I am thinking maybe this isn't possible, but i hope it is because it would be an insanely good development environment. Any thoughts
VIEWS ON THIS POST

213

Posted on:

Thursday 25th October 2012
View Replies!

reading iptc metadata with as3

hello. is it possible to read the iptc metadata of a jpeg loaded with as3
VIEWS ON THIS POST

199

Posted on:

Thursday 25th October 2012
View Replies!

[cs4][3d] as3 equivalent of global/local option

Hi! If I change some 3d property via as3, how do set the global/local option usually available under the tools palette Is there a way
VIEWS ON THIS POST

245

Posted on:

Thursday 25th October 2012
View Replies!

as3 Tweening Head-scratcher

Hi . here is a wierd one for you. I cant get my head around it. Im trying to create an animated carosel type thing. I have a main class that loads xml and then external images into a class I called Image which is just really a wrapper for Loader. I have a previous and next buttons that use array methods to move the Image instances around in an array and then sends the correct Image to 3 classes that represent my 3 image positions in my carousel. Heres the important snippet in my main class: Code: private function onPrev(e:MouseEvent):void { _images.unshift(_images.pop()); for (var i:int = 0; i
VIEWS ON THIS POST

190

Posted on:

Thursday 25th October 2012
View Replies!

Flash as3 application Examples

Can you please give me the best sites/examples of as3 application..
VIEWS ON THIS POST

195

Posted on:

Thursday 25th October 2012
View Replies!

as3 physics issue

! The thing is i'm trying to make an effect that emmulates hanging interactive objects so that when the user hits any object it moves according to the mouse position and speed. My problem is that i cant find the way to apply the tension and the "pendulum" kind of movement so it looks natural. any thoughts thanx alot!
VIEWS ON THIS POST

124

Posted on:

Thursday 25th October 2012
View Replies!