Solved

Urgent!!! Center the dynamic image in flash (500 points now)

Posted on 2006-06-18
5
149 Views
Last Modified: 2012-05-05
Hi everyone,

I'm trying to load images from a flash, but cant center the image, here's my actionscript:

loadMovie(image.jpg, _root.photo);
l = _root.photo.getBytesLoaded();
t = _root.photo.getBytesTotal();
while (l < t)
{
     //do nothing
}
_root.photo._x = (550-_root.photo._width)/2;
_root.photo._y = (400-_root.photo._height)/2;

the images show up, but still on the top left corner.

Anyone knows how to center the image?

Thanks
Harry
0
Comment
Question by:eezy2
  • 2
  • 2
5 Comments
 

Author Comment

by:eezy2
ID: 16932410
hello, anyone got ideas?

Thanks
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16933194
Hi,

this code will work fine for you
-----------
w = _root.photo._width;
loadMovie("image.jpg", _root.photo);
l = _root.photo.getBytesLoaded();
t = _root.photo.getBytesTotal();
_root.onEnterFrame = function()
{
      if (l == t && _root.photo._width>w)
      {
            _root.photo._x = (Stage.width-_root.photo._width)/2;
            _root.photo._y = (Stage.height-_root.photo._height)/2;
            delete _root.onEnterFrame;
      }
};
-----------

Rgds
Aneesh
0
 

Author Comment

by:eezy2
ID: 16933291
nah, didn't work, sorry aneesh.

or maybe i did it in the wrong way?
0
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 300 total points
ID: 16939956
Here I have uploaded working version..
http://www.4shared.com/file/2127922/43d5ae53/loadimageincenter.html

download and compare what you have done wrong


Rgds
Aneesh
0
 
LVL 12

Assisted Solution

by:SamuelRostol
SamuelRostol earned 200 total points
ID: 17478029
Try changing it to:

w = 0;
image = loadMovie("image.jpg", _root.photo);
l = image.getBytesLoaded();
t = image.getBytesTotal();
_root.onEnterFrame = function()
{
     if (l >= t && _root.photo._width>w)
     {
          image._x = (Stage.width - image._width)/2;
          image._y = (Stage.height - image._height)/2;
          delete _root.onEnterFrame;
     }
};
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question