iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Flash Discussion Forum Flash design presents a limitless number of possibilities for your sites and designs. Discuss your Flash ideas, questions and issues here.

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-29-2004, 08:38 PM
WebProWorld Member
 
Join Date: Aug 2004
Posts: 26
leandroaliaj RepRank 0
Default Help with ActionScript

Hello everybody,

I am trying to make a system that loads a JPEG when a button is pressed. That is simple. But i have 38 buttons, and the problem is that whenever a new JPEG is loaded, it is not aligned as i want it to. Whatever i do it doesn't seem to align right. I want it to be put in the center of the stage. Here is my code:

//create the buttons
pic1.whichPic = 1;
for(i = 1; i <= 37; ++i){
pic1.duplicateMovieClip("pic" + (i + 1), i);
_root["pic" + (i + 1)]._x = _root.pic1._x + (i * 14.3);
_root["pic" + (i + 1)].whichPic = (i + 1);
}

//this function is called whenever one of the buttons is released
function releace(whichPic){
loadMovie("pictures/recentPaintings/picture" + whichPic + ".jpg", "image");
image._x = horizontalMiddle - (image._width / 2);
}

But this is not working, can anyone find a solution?

Thanks a lot,
Leandro
__________________
Web Hosting by HostoSapiens - 5,95€/month
1000MB storage, 40GB bandwidth, 500 emails, PHP, MySQL, FrontPage and more
Reply With Quote
  #2 (permalink)  
Old 08-30-2004, 01:17 PM
esiegel's Avatar
WebProWorld Pro
 
Join Date: Jul 2003
Location: New York
Posts: 109
esiegel RepRank 0
Default

a .jpg file should load with it's top left corner at the origin (0,0) point of the movie clip it is loading into.

By default this point is in the CENTER of the movie clip. Move that point to the top left corner of the movie clip and the .jpg should load correctly.
__________________
Ed Siegel - Business Information Manager
Ampacet Corporation
http://www.Ampacet.com
Reply With Quote
  #3 (permalink)  
Old 08-30-2004, 01:19 PM
WebProWorld Member
 
Join Date: Aug 2003
Location: UK
Posts: 51
poab RepRank 0
Default

Hi,

This isn't really too difficult, but there's a couple of things to bare in mind:

1) loadMovie executes last in a statement block, regardless of where you place it, so that what you've actually written is:

function releace(whichPic){
// note the switch of position
image._x = horizontalMiddle - (image._width / 2);
loadMovie("pictures/recentPaintings/picture" + whichPic + ".jpg", "image");
}

meaning that your script is evaluating prior to the image being loaded.

2) You need to wait until the image is loaded before calculating the position. Even if you're loading it off your machine, the actionscript will still execute faster.

The two obvious solutions are onLoad and onData for example:

image.onLoad = function(){
//position code here
}

However, this won't work because loadMovie removes everything in the target movie clip. On top of which, you can't place the onLoad after the loadMovie because, as I said further up the post loadMovie ALWAYS executes last in the statement block.

There's three possible solutions to this, 1) Use prototype (illegal in AS2.0 and complex) , 2) Use setInterval or 3) Use onEnetrFrame to keep checking if the jpg is loaded.

_______________________________________________

So...now I've said that here's what I'd suggest you use:

function releace(whichPic){
loadMovie("pictures/recentPaintings/picture" + whichPic + ".jpg", "image");
_root.onEnterFrame = function(){
if(image.getBytesLoaded()>=image.getBytesTotal){
image._x = (Stage.width/2)-(image._width/2);
delete this.onEnterFrame;
}
}
}

Note that this assumes that you don't currently have an onEnterFrame running on the _root if you do, either put it somewhere else (except on the image mc for the same reasons outlined above for the onLoad) or createEmptyMovieClip() and stick it on there.

If you want the thing centered in the browser window instead of the stage take a look at this tutorial:
http://www.actionscripts.co.uk/tutor...b04/stage.html

cheers.
Reply With Quote
  #4 (permalink)  
Old 08-30-2004, 05:55 PM
WebProWorld Member
 
Join Date: Aug 2004
Posts: 26
leandroaliaj RepRank 0
Default

esiegel i can't do that because not all JPEGs have the same dimensions.

poab i will try what you said. Note that i did try this way too and it still didn't work:

function releace(whichPic){
var clipLoader = new MovieClipLoader();
var myListener = new Object();
clipLoader.addListener(myListener);
clipLoader.loadClip("pictures/recentPaintings/picture" + whichPic + ".jpg", "image");
myListener.onLoadComplete = function(){
image._x = 290 - (image._width / 2);
}
}

can't understand why

thanks for the help guys i will let you know if it worked
__________________
Web Hosting by HostoSapiens - 5,95€/month
1000MB storage, 40GB bandwidth, 500 emails, PHP, MySQL, FrontPage and more
Reply With Quote
  #5 (permalink)  
Old 08-31-2004, 08:08 PM
WebProWorld Member
 
Join Date: Aug 2004
Posts: 26
leandroaliaj RepRank 0
Default

poab your code worked fine

Thanks!
__________________
Web Hosting by HostoSapiens - 5,95€/month
1000MB storage, 40GB bandwidth, 500 emails, PHP, MySQL, FrontPage and more
Reply With Quote
  #6 (permalink)  
Old 09-01-2004, 08:19 AM
WebProWorld Member
 
Join Date: Aug 2003
Location: UK
Posts: 51
poab RepRank 0
Default

You're welcome :)
Reply With Quote
Reply

  WebProWorld > Site Design > Flash Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 05:45 PM.



Search Engine Optimization by vBSEO 3.3.0