Centering Content But Scale Rest Of Stage
hi there,
i'll having heavy problems in achieving a very often seen functionallity.
i'll have swf which contains the following:
- a black bg (just the preset bg, no mc) - an image - a mc containing content (incl. pixelfonts)
what i'm trying to achieve is the following:
- making the movie scale when the broswer window gets resized - making the image always top left (ot right) of browser window - centering the content within the browser window x and y wise - if possible add some laco or some tweening
i tried alot of script found here and also elsewhere on the web, but i wasn't able to get it to work. i know how to center something with stage.width/2 and such, but this doesn't work when resizing the browser
any help would be apprechiated
cobo
ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 02-03-2007, 10:21 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
AS3 - Content Centering/stretching/scaling On Stage Resize?
Hi guys,
I'm trying to develop a Flash site that has these characteristics:
1. Populates 100% of browser window real estate.
2. Holds content that is unscalable, but stays centered no matter how large the window is.
3. Also has content that stretches (header and footer) to the width of the window, but doesn't scale vertically.
I have an idea of how to do each of these in AS3, but every time I've attempted them I usually end up failing horribly.
Can anyone tell me a "best practice" method for pulling this off?
Main Stage Dimentions Does Not Match With The Rest
Hello,
I just open a new project in Flash. Set the dimensions of main stage to 1000x800.
Than I created a movie clip symbol, which will be page1 of new website. Dimensions are 1000x800. There I import various graphics to design that page. When I import that page1(movie clip symbol) on the main stage, it is much bigger than main stage. So that page1 does not fit on main stage. Could anyone tell me, what I do wrong or how to solve this problem?
Thank you so much for any input and I appologize for such basic question.
Cheers
Janek
Centering Scale Transformation
I need to centre the transformation applied by the transform matrix in AS3. E.g centre at bottom, bottom right, some point x,y in bounding box. How can I set this attribute ?
Stage Scale, Element Don't Scale
i got this color-changing background, and I have it fit into the browser window at 100% scale, so it scales proportional to browser window.
and then,
i got the content element on top of this color changing bkg, but i want it to remain unscaled... while always remain at the centre of the stage.
i am having this bkg and content in the same fla....
what can i do to seperate these two command ?
i did try
Stage.scaleMode = "noScale";
but it affects the background as well.
Stage Scale, Element Don't Scale
i got this color-changing background, and I have it fit into the browser window at 100% scale, so it scales proportional to browser window.
and then,
i got the content element on top of this color changing bkg, but i want it to remain unscaled... while always remain at the centre of the stage.
i am having this bkg and content in the same fla....
what can i do to seperate these two command ?
i did try
Stage.scaleMode = "noScale";
but it affects the background as well.
Stage Scale, Element Don't Scale
i got this color-changing background, and I have it fit into the browser window at 100% scale, so it scales proportional to browser window.
and then,
i got the content element on top of this color changing bkg, but i want it to remain unscaled... while always remain at the centre of the stage.
i am having this bkg and content in the same fla....
what can i do to seperate these two command ?
i did try
Stage.scaleMode = "noScale";
but it affects the background as well.
Scale Proportion Past Stage But Not Below Stage
This goes out to Scotty or any other guru floating around out here.
I need the image_mc movieclip in this .fla to scale to fit browser, however i need the image to scale in proportion. I would also need a listener of sorts that will NOT allow the image_mc movieclip to scale below the stage size of 1024 x 768.
Can anyone drop some science on me?
http://www.spent2000.com/scale_propo..._for_stage.fla
Thanks in advance.
- 400x5
Stage.align And Stage.scale(X,Y) Algorithms
Hello, I'm after a good way to take a image scale it to where:the image scale propotionately (image.scaleY == image.scaleX);
the image must scale to fit the browser, But.
the image must not leave empty areas of the stage exposed (upscale the image if needed to cover blank stage area exposed, which will clip off a end of the image and thats where Stage.align comes in)
the stage.align will help give scale orientation, meaning from what direction will the image scale. This is important since this can cause a few problems with centering of the image upon rescale and you also want to know what end is most likely to get clipped off in the event that the image needs to upscale to cover blank stage areas.
as I have it now
_imageHolder is a hypothetical image and stage is a reference to the stage.
I know this algorithm is not a best practice and it don't cover the stage completely. Any help would be great.
PHP Code:
if((_imageHolder.width >= stage.stageWidth) && (_imageHolder.height >= stage.stageHeight)){ if(_imageHolder.width >= stage.stageWidth){ _imageHolder.width = stage.stageWidth; _imageHolder.scaleY = _imageHolder.scaleX; }else if(_imageHolder.height >= stage.stageHeight){ _imageHolder.height = stage.stageHeight; _imageHolder.scaleX = _imageHolder.scaleY; } }else if((_imageHolder.width <= stage.stageWidth) && (_imageHolder.height <= stage.stageHeight)){ if(_imageHolder.width < stage.stageWidth){ _imageHolder.width = stage.stageWidth; _imageHolder.scaleY = _imageHolder.scaleX; }else if(_imageHolder.height < stage.stageHeight){ _imageHolder.height = stage.stageHeight; _imageHolder.scaleX = _imageHolder.scaleY; } } }
This event will be in a function that fires when the stage rescales or when the image loads.
Also what is a good idea to deal with the stage.align problems that can come up?
[F8] Centering Content
Does anyone have any idea how to center all of the content of a movie except the background image? I've attached the following code in the main timeline so the background goes full frame, but it forces the content into the top left. I'd like that to float in the center of the browser.
// this tells Flash NOT to allow the assets to be scaled
Stage.scaleMode = "noScale";
Stage.align = "TL";
// need to set up a listener object to say when the stage is resized.
var stageListener:Object = new Object();
Stage.addListener(stageListener);
setBackground();
// called when the stage is resized
stageListener.onResize = function() {
setBackground();
}
function setBackground() {
// determine middle
var middleX = Stage.width/2;
var middleY = Stage.height/2;
// reposition the bkgd to middle
bkgdMC._x = middleX;
bkgdMC._y = middleY;
// scale background to fit width and height
bkgdMC._width = Stage.width;
bkgdMC._height = Stage.height;
// see if it grew bigger horizontally or vertically and adjust other to match
// to maintain aspect ratio
bkgdMC._xscale > bkgdMC._yscale ? bkgdMC._yscale = bkgdMC._xscale : bkgdMC._xscale = bkgdMC._yscale;
}
[F8] Centering Content
Does anyone have any idea how to center all of the content of a movie except the background image? I've attached the following code (below) in the main timeline so the background goes full frame, but it forces the content into the top left. I'd like that to float in the center of the browser. Here's what I've got so you can see what I mean:
http://www.sugrue.com/new
// this tells Flash NOT to allow the assets to be scaled
Stage.scaleMode = "noScale";
Stage.align = "TL";
// need to set up a listener object to say when the stage is resized.
var stageListener:Object = new Object();
Stage.addListener(stageListener);
setBackground();
// called when the stage is resized
stageListener.onResize = function() {
setBackground();
}
function setBackground() {
// determine middle
var middleX = Stage.width/2;
var middleY = Stage.height/2;
// reposition the bkgd to middle
bkgdMC._x = middleX;
bkgdMC._y = middleY;
// scale background to fit width and height
bkgdMC._width = Stage.width;
bkgdMC._height = Stage.height;
// see if it grew bigger horizontally or vertically and adjust other to match
// to maintain aspect ratio
bkgdMC._xscale > bkgdMC._yscale ? bkgdMC._yscale = bkgdMC._xscale : bkgdMC._xscale = bkgdMC._yscale;
}
Hiding/Masking Off-stage Content (external Content)
Hi,
I'm loading an image gallery into another movie. The image gallery itself uses XML to generate a row of thumbnails dynamically. In it's own player, this is fine, but when loaded into the larger movie, the row of thumbnails extends far beyond the container clip.
I've set the size of the container clip with an onLoad function, but I have no idea how to appropriately mask it so there is no spillover. Using a mask in the gallery clip doesn't work because the gallery is 100% scripted (unless I'm missing something terribly basic).
Is there a general method to use, aside from creating infinitely large opaque boundaries around the stage?
Thanks for any tips or insight!
Centering A Swf Above Html Content
I need to have a swf act like a pop-up and sit over html content, invisible until a link is clicked. Using DIVs and z-index I was able to do this, but only with absolute positioning. How can I get the swf to remain centered in the browser window rather than just a given distance from the side and top?
Centering Content In Scrollpane
i notice whenever i make content in a scrollpane, and the scrollpane size is wider than the content is, the content will justify on either the right or left side of the pane. is there any way to center the content?
Centering Content With LoadMovie
10 buttons load 10 different sized Jpegs into an MC which is 500x500 using loaMovie.
How can I get these clips to load with their centers aligned with the MC's center rather than their top left corners aligned with the MC's top left corner.
Thanks
Centering Content In An Imageholder
I'm using the following code for a picture viewing loading external pictures using xml.
_root.createEmptyMovieClip("mcImageHolder",1);
mcImageHolder._x = 10;
mcImageHolder._y = 40;
is it possible to center the pictures in the placeholder instead of using x and y values??
Centering Content On A Page?
that's not a very good title for what i'm trying to explain...so bare with me for a bit...
i want my flash movie to come up in the browser at 100% width and height...so it takes up the entire browser window...
what i can't figure out is how i keep my content always centered in the middle of the window? and even more than that...keeping ALL the various navigational elements together and having them automatically resize according to the size of the browser window...
i've been more than successful at having the various objects resize, but, they are sticking to more or less relative positions...
i hope that makes sense...
any ideas are much appreicated...thanks...vaska
Centering Flash Content
I'm a real novice with Flash so my question is probably a little basic but here it is.
When I upload my site (all flash) to my server and then look at it in a browser - the body of the page is flush left and not centered. So even when I expand my window it stays flush left. How do I change that so that it is centered?
Centering Loaded Content
ok here's my problem,
I have an index.swf that it's dimensions are 1020x610, now when I load content in a container in the index.swf it will be centered using an onResize stage listener, that works fine but only if the loaded content is 1020x610, I've also used an onEnterFrame that checks if the width and height are !=0 so that way it waits for it to load before centering the content.
What should I do to always keep my content centered. Lets say I want to load a swf that is smaller (ie the 1st frame only contains 1 element that is smaller than the stage dimensions) I'm not sure if I'm explaining this well....
Content Not Centering On First Load (FBF)
I've got a full browser flash project I'm having some problems with.
I've got a main movie that loads a background image (that gets stretched to fill the browser window) then it loads up a header and content box.
The problem is, the content box does not load in the center when the page is first loaded. If I resize my browser, it then calculates and centers it.
At first all I did was took the AS that calculated and placed the movie at the center of the screen and placed it on an onClipEvent (load) handler right on the empty movie clip that loads in the content but that's not working anymore for some reason.
Here's my AS:
ActionScript Code:
Stage.scaleMode = "noscale";Stage.align = "TL";loadMovie("dh_mainContent.swf","mainContent_mc");loadMovie("header.swf","mainHeader_mc");stageListener = new Object();stageListener.onResize = function () { var stageXCenter = Stage.width * .5; var stageYCenter = Stage.height * .5; stageXCenter = stageXCenter - (_root.mainContent_mc._width * .5); stageYCenter = stageYCenter - (_root.mainContent_mc._height * .5); _root.mainContent_mc._x = stageXCenter; _root.mainContent_mc._y = stageYCenter;}Stage.addListener(stageListener);bg.onResize = function() { var imageAspectRatio = this._width/this._height; var stageAspectRatio = Stage.width/Stage.height; if (stageAspectRatio>=imageAspectRatio) { this._width = Stage.width; this._height = Stage.width/imageAspectRatio; } else { this._height = Stage.height; this._width = Stage.height*imageAspectRatio; } this._x = Stage.width/2; this._y = Stage.height/2;}Stage.addListener(bg);bg.onResize();
Any ideas?
Centering Content In The Browser
Hi Everyone,
I found a tutorial on centering content but I don't think I'm using it right. Anyone know how to center content in a browser?
Best
monique
Centering Content In Flash MX
Hey guys,
I've just created an intro movie in Flash and it works perfectly... except for one thing. I found out that I needed to increase the size of the stage and when I did, flash automatically puts my content into the upper left of the stage. I've got tons of individual symbols on the page, is there a way that I can take everything I've done and put it in the center of the stage without having to go back and re-center it all individually? So far nothing I've tried works.
Passing A ...rest To A ...rest Parameter
Hi, I'm trying to extend the functionality (not extend the class itself) of the netconnection.call() function by enclosing a netconnection instance in a class.
What I'm attempting to do is have a function that I have defined as "call" make a call to mynetconnection.call("", null, ...rest). For example:
Code:
public function call(method:String, ...rest):void {
this.mync.call(method, null, rest);
}
I have tried repeatedly to do this, and it's not working. The rest parameter feeds the parameters into an array, but is there any way to undo that on the inside of the method and pass a pseudo-list of parameters to nc.call() so that it will see it correctly?
Is it possible to duplicate the functionality of a ...rest parameter into another function?
- TK
Centering The Stage
ok....this is totally a newbie Q.
How do you people center the stage? Everytime I preview mine it goes to the left. I know I can center it by going into the sourcecode and change the html but I would like it to stay permanently in the center.
Maybe I should just do all my stuff and when it's done only then change the code? But then again, I can't really see whether it will look ok or not?
any help?
tq
Centering In The Stage
Hi, I have an image gallery but at the moment the image is aligning top left in the window. I would like it to center in the stage if possible.
The code I have at the moment is:
function setPositions () {
container.img._x = (Stage.width-container.img._width)/2;
container.img._y = (Stage.height-container.img._height)/2;
}
Could some one please help me with the right code to center the container in the stage?
THanks in advance, it's really appreciated!
pj
Centering Content In Scroll Pane
I'm using a scroll pane in MX with an image that is about twice as wide as the pane. Is there a way to have the image centered horizontally within the pane as the default?
Centering Content In Browser Window
Hi everyone,
I'm trying to build a flash site where the content sits centrally in the browser window, so whatever screen size the viewer has, or however they resize their browser window the content sits centrally.
This code works in part...
Stage.scaleMode = "noScale";
// Create an object to receive the screen events
stageListener = new Object();
// Assign a listener for the Stage object
Stage.addListener(stageListener);
// Create a function for the event you want to listen for
stageListener.onResize = function() {
// Get the width and height of the stage
// & multiply by half
var stageXCenter = Stage.width*.5;
var stageYCenter = Stage.height*.5;
// place the clip
_root.main_movie._x = stageXCenter;
_root.main_movie._y = stageYCenter;
};
This code works perfectly, but only once the user has changed the size of their window. When the page first loads it is positioned top left, as soon as the browser window is dragged the code kicks in and positions the movie properly. Can anyone suggest a change that will pick up the size of the browser window and position the content when the page first loads???
Thanks for you help.
Auto Centering Content In Flash
Hello,
I went to this site, www.2210media.com and noticed his content auto centers to the browser window size. Anyone know how he does it.. it's definitely in the actual .swf code cause by itself it does it also:
http://www.2210media.com/main/swf/new2210.swf
Thanks in advance for any help!
Centering Flash Content In Browser
Hi there, I am trying to center the flash content i created in a browser, usually what i do is after publishing the fla file in html, I would edit the html file and add some lines to center the content in the browser. I learned this from a book.
Now however i published the HTML file in flash HTTPS template that detects whether you have the correct version of flash player and when i tried to edit the HTML file, i realised that the way the HTML code is written is very different (much more complicated) compared to a HTML file published without flash player detection, and I tried playing around to c if I was able to center the content with the method I learned from the book but I couldn't get the browser to center the content. Can anyone help me on this......
Any help would be greatly appreciated! THank you!
Regards,
Wen
Centering Content On Browser Resize
Hi. I have my main flash .swf set to 1024 x 700 pixels. I have a movie clip that goes from one end to the other at the bottom and another movie clip at the top (which I want centered). Plus, I want the bottom movie clip to resize when the browser window is resized. I don't want the top movie clip to resize at all. Is this possible?
I manually changed the width and height of the .swf in the source code to 100%. But the main .swf does not resize when the browser window resizes.
Here's my code for the main .swf:
Stage.align = "TL";
Stage.scaleMode = "noScale";
sizeListener = new Object();
sizeListener.onResize = function() {
trace (Stage.width)
trace (Stage.height)
};
Stage.addListener(sizeListener);
What code do i put for the bottom movie clip?
Centering Dynamicly Loaded Content
Well, I load content into my empty movieclip, but I need that movieclip as a center and not as a left top corner registration point.....
This really drives me insane, as I can't find a sollution anywhere, so maybe you can help me out with some divine magic!!
SWFObject: Centering Alt Content In Browser
Hello:
I have been working on migrating from the old Flash embed code to SWFObject. I have centered the Flash content in the browser using CSS, and is positioned where it should be:
<style type="text/css">
<!--
DIV.flash
{
position:absolute;
left:50%;
top:50%;
width:800px;
height:600px;
margin-left:-400px;
margin-top:-300px;
background-color:#000000;
}
-->
</style>
The problem: Now the original alternate keyword-rich content for the search engines is not centered. The upper left-hand corner of the alt content is pinned to the center of the page. I need to be able to center the alt content as well as the Flash movie.
How do I do this? another <div> class? - kind of like the milov.nl example elsewhere in this forum?
http://www.milov.nl/code/css/verticalcenter.html
Centering Loader Component Image Content
Here is a little bit of as2 code how to centering Loader Component:
var mainw:Number = Stage.width/2;
var mainh:Number = Stage.height/2;
myLoader.scaleContent = false;
myLoader.visible = false;
var ldrlistenerObject = new Object();
ldrlistenerObject.complete = function(evt_obj:Object) {
myLoader.visible = true;
var imagew:Number = myLoader._width/2;
var imageh:Number = myLoader._height/2;
myLoader._x = mainw-imagew;
myLoader._y = mainh-imageh-60;
};
myLoader.addEventListener("complete", ldrlistenerObject);
Centering On Stage Issue
hello
i am trying to center the whole movie on the stage and its not quite working out the way it should.
i think the code needs tinkering with but i have tried doing so to no avail. Here is the code, and if you follow the link below also, you can see the site i have done, and when you resize the screen you will see the movie slips out of the frame.
Code:
stop();
Stage.scaleMode = "noscale";
Stage.align = "TL";
var resize_lis:Object = {};
resize_lis.onResize = resizeClips;
Stage.addListener(resize_lis);
function resizeClips():Void {
_root.myHeader_mc._width = Stage.width;
_root.myFooter_mc._width = Stage.width;
_root.leftLine._height = Stage.height;
_root.rightLine._height = Stage.height;
_root.topLine._width = Stage.width;
_root.botLine._width = Stage.width;
}
resizeClips();
Stage.addListener({onResize:reposition});
function reposition() {
var header = _root.myHeader_mc;
var footer = _root.myFooter_mc;
var photo = _root.photo;
var nPos;
nPos = getNewPosition(header);
header._x = nPos.x;
header._y = 0;
nPos = getNewPosition(footer);
footer._x = nPos.x;
footer._y = Stage.height-footer._height;
var mc = _root.photo;
var newX = Math.floor((Stage.width-mc._width)/2);
var newY = Math.floor((Stage.height-mc._height)/2);
mc._x = newX;
mc._y = newY;
var mc = _root.leftLine;
var newX = Math.floor((Stage.width-mc._width)/2);
var newY = Math.floor((Stage.height-mc._height)/2);
mc._x = newX;
mc._y = newY;
var mc = _root.rightLine;
var newY = Math.floor((Stage.height-mc._height)/2);
var newX = Math.floor((Stage.width-mc._width)/2);
mc._x = newX;
mc._y = newY;
var mc = _root.topLine;
var newY = Math.floor((Stage.height-mc._height)/2);
var newX = Math.floor((Stage.width-mc._width)/2);
mc._x = newX;
mc._y = newY;
var mc = _root.botLine;
var newY = Math.floor((Stage.height-mc._height)/2);
var newX = Math.floor((Stage.width-mc._width)/2);
mc._x = newX;
mc._y = newY;
}
function getNewPosition(mc) {
var newX = Math.floor((Stage.width-mc._width)/2);
var newY = Math.floor((Stage.height-mc._height)/2);
return {x:newX, y:newY};
}
reposition();
this.onLoad = function() {
_root.clicked = false;
};
http://www.changthai.org/test/netcones12.html
thanks.
What's The Best Way Of Centering This Video On Stage?
Hello to all,
What's the best way of positioning stuff in the center of the stage in Flash? I have seen
various bits of code on how to do this but the code does not work for my sitution. My situation
is as follows:
I am trying to build a Flash video player and I've got all the other stuff working including
scrubbing etc. My Flash document dimensions are 320 by 280. I can center the video initially
in the onMetaData event but my client decided to punish me by demanding that he be able to alter
the SWF dimensions dynamically using JavaScript after embed time. This causes big problems for me because the
damn thing just does not center after the resize. I have set the
stage.scaledMode = StageScaleMode.NO_SCALE so that I can handle the onResize event.
Right now I'm trying to embed the movie using the size 512 by 322 initially and it just does not center.
Remember that my original Flash doc is 320 by 280. So can someone put me out of my misery because I'm
now going insane. Have I missed anything? I have only started to develop in AS3 in the past month.
The other day I went to bed at 630 a.m. in the morning because of this problem. Please help.
Surely there must be some form of UI layout managers in Flash like the wonderful Java Swing ones.
Thanks,
Ernest
Centering A ContainerMc On Stage
Simple and silly question:
How can I get a ContainerMC (which loads images in and resize to fit the image size) dinamically centered in relation to Movie Stage width and height?
PHP Code:
ContainerMC _x = Stage.width-(this._width/2);
ContainerMC _y = Stage.height-(this._height/2);
?
Centering A Sprite On Stage Help
Trying to understand AS3 by example. Tough when the examples aren't working properly
Can you point out what I'm doing wrong here (this code was lifted from a tutorial online somewhere).
Code:
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.display.Graphics;
var ball:Sprite = new Sprite();
addChild(ball);
ball.graphics.lineStyle(3,0x000000);
ball.graphics.beginFill(0xFFCC00);
ball.graphics.drawCircle(20, 20, 40);
ball.graphics.endFill();
function resizeHandler(e:Event):void {
ball.x = (ball.stage.stageWidth/2) - (ball.width / 2);
ball.y = (ball.stage.stageHeight / 2) - (ball.height / 2);
}
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, resizeHandler);
stage.dispatchEvent(new Event(Event.RESIZE));
Thanks !!
Centering The Stage In A Web Browser
Hey,
I have a really wide flash page, but the main portion of it is in the center
of the .swf. My question is how do I make the center of my .swf in the center
of a web browser so that when the user resizes the browser, the center of the stage stays in the center of the browser? Right now it has the left side of the .swf aligned with the
left edge of the browser so the center of my .swf is usually being cut off by
the right edge of the browser and users have to scroll to the right to see the
main portion of the site...I'm sorry if that's somewhat confusing, but any help
at all would be appreciated. Thanks!
Dave
Centering Content Inside A Dynamically Created Movieclip
Like the title says, I'm having trouble to center any dynamic content (movieclips, textfields...) inside a dynamically created movieclip, which has a default point of interested in the top left corner.
Do you have any solutions?
Thanks
PS: Just as an example, I have a dynamically created text field inside a dynamically created movieclip....and when I try to scale that movieclip I need to scale it from its center
Centering A Textfield On The Stage Using Actionscript
Hi,
I have been trying to figure out how to center a dynamic textfield on the stage using actionscript. I have tried several ways but can't seem to figure it out.
Does anyone have any suggestions on how to do this in actionscript?
You assistance is appreciated.
Thanks,
- Alex
Stage Object? Centering Movie
I just saw this featured link on the site that reminded me of something I've been wondering about in Flash. This is the link:
http://www.curvemusic.ca/
And I have seen other sites that do the same thing:
http://www.kurtnoble.com/
http://www.bukwild.com/
http://www.fabrislane.co.uk/launch.html
Basically, if you notice, the main part of the site is centered on the screen. But the entire page (including the background) is part of the flash file. If you resize your window it doesn't scale the movie, it just reveals more of the background and re-centers the content. Is this done using the stage object in actionscript? Can anyone provide an example or point me to a tutorial on how this is done?
Centering Mouse On Stage + Timer
I'm trying to come up with a remedy to make the mouse mc that start in the center of the movie rather than start in the top left (0,0 coordinate) - than after 5 sedonds if the mouse mc isn't in the center it re-centers itself
any help will be appreciated. i've tried setting the _y&x mouse but to no avail.
thanks in advance
Problem With Centering Image On Stage
I am dynamically loading an image onto the stage. I load the image from an XML file into an empty MC. Inorder to center it I get the width of the empty MC with the loaded image, subtract that from the stage width, then divide by 2. The math works, but for some reason its saying the width of the empty MC is 0. So this isn't working. Any suggestions.
Here is my code:
Code:
_parent._parent.attachMovie("mainPhoto","mainPhoto",1000);
_parent._parent.mainPhoto.loadMovie(picture);
_parent._parent.mainPhoto._x = (650 - _parent._parent.mainPhoto._width) / 2;
_parent._parent.mainPhoto._y = 85;
Centering On Stage - Unexpected Behaviour
I have a function that takes a MC and centers it on the stage:
ActionScript Code:
function CenterOnStage(mc:DisplayObject):void{
mc.x = (stage.stageWidth-mc.width)/2;
mc.y = (stage.stageHeight-mc.height)/2;
}
Do you see anything wrong with it? I think it works fine.
Now i have a MC that i always want to have centered on my stage. So i do:
ActionScript Code:
stage.addEventListener(Event.RESIZE, UpdateStage);
function UpdateStage(e:Event):void{
CenterOnStage(main);
}
where, "main" is the MC i want centered. The thing is that when i maximize and then restore again the browser, this "main" moves about 50 pixels up and stays there... Even if i play again with the browser size (stage.stageWidth...) it stays up there... Can anyone see the reason? Or maybe propose another way to achieve this?
Thx
(ps: i dont know if it matters but i assign the eventListener in a function, after something has been clicked. Just mentioning)
Centering Movie Clips On Stage
Im having trouble centering my movie clips on the stage.
I have postioned movie clip holders on the stage and and coded them to be invisible (10 of them). If the images loaded are less than 10, the extra movie clip holders stay invisible and the loaded ones become visible.
I am struggling to center the visible movie clip holders.
Here is my code:
ActionScript Code:
for (var i = 0; i<10; i++) {
this["cand_"+i].visible = false;
}
var loader:Loader;
var xmlR:XML;
var xmlListR:XMLList;
var xmlLoaderR: URLLoader = new URLLoader();
xmlLoaderR.load(new URLRequest("images_full.xml"));
xmlLoaderR.addEventListener(Event.COMPLETE, xmlLoaded2);
function xmlLoaded2(event:Event):void {
xmlR = XML(event.target.data);
xmlListR = xml.plonker.candidate;
//trace(xmlList);
var numCandidates = xmlListR.length();
for(var i:int=0; i<xmlListR.length(); i++){
var loader:Loader = new Loader()
this["cand_"+i].addChild(loader)
loader.load(new URLRequest(xmlListR[i].attribute("thumb")));
this["cand_"+i].visible = true;
var totalWidth:Number = this["cand_"+i].width * i;
this["cand_"+i].x = stage.stageWidth/2 - totalWidth/2;
}
}
I am going wrong at "this["cand_"+i].x = stage.stageWidth/2 - totalWidth/2;"
The above code centers the movie clips, but the x value of mc's start halfway through the mc, positioning it hafway through each mc.
Please advise on centering mc's.
Centering A Few Buttons After Stage Re-size?
I have 3 buttons consisting of text and centered on ths stage. THey also have hit areas larger than the area occupied by the text. Now I have changed the size of the stage and I would like to center them again on the stage, and also have their hit areas move with them. Is there a way to do this? I cannot figure out how to do it.
G
Centering Mouse On Stage Timer
anyone have a code that will center the mouse when flash starts? the cursor is always in the top left of the movie on the 0,0 coord
i tried making a mc and setting the properties of the mouse mc to the center but to no avail. also would like the functionality that if resets the cursor to the middle after 5 or so seconds if the cursor is moved off the stage.
thanks
Centering A Loaded Swf In The Middle Of Stage
How come loaded the slave.swf is not in the center of the browser window?
The master.swf that loads the slave uses the entire browser window.
ActionScript Code:
//Stage.align = "TL";
Stage.scaleMode = "exactFit";
Stage.showMenu = false;
_level0.createEmptyMovieClip("mcEmpty", this.getNextHighestDepth());
mcEmpty.loadMovie("swf/welcome.swf");
mcEmpty._x = (Stage.width - mcEmpty._width)/2;
mcEmpty._y = (Stage.height - mcEmtpy._height)/2;
Centering A Nested Object To The Stage.
hoy hoy,
I have a picture of a mine which is nested within an object, nested within another obect. Now what i want it that on the keypress of shift, i creates the mine image at the same postion of the tank.
The issue is that the main obect that is nesting the mine moves, thus not creating at the the center, rather on that postion of the object.
here are how my images go by instance names;
1. Tank Stays in the center
//////
/////
1. Land (moves) -- 2b. map -- 3b. All objects that hitTest
|
2a. Objects
|
3b. All the objects that dont get hit(in here is my mine.)
|