# "Refreshing" function to resize img?

**URL:** <https://forum.kirupa.com/t/refreshing-function-to-resize-img/199020>\
**Category:** flash\
**Created:** [August 30, 2006, 4:37pm UTC](https://forum.kirupa.com/t/refreshing-function-to-resize-img/199020 "2006-08-30T16:37:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![thalamus](https://avatars.discourse-cdn.com/v4/letter/t/0ea827/32.png) [@thalamus](https://forum.kirupa.com/u/thalamus)\
**Post date:** [August 30, 2006, 4:37pm UTC](https://forum.kirupa.com/t/refreshing-function-to-resize-img/199020/1 "2006-08-30T16:37:51Z")

</div>

[SIZE=1]Hello:

I have a movie clip containing thumbnails. When you click on a thumbnail it loads the full-size image into a container in a 2nd movie clip called itemdetails\_mc and resizes and recenters it to fit in the container. A watermark MC is displayed at the bottom of the resized image, scaled to the same width as the resized image while maintaining aspect ratio.

Both the thumbnails MC and the itemdetails\_mc are on the main Timeline.

I set the display of itemdetails\_mc to the onRelease function of itemdetails\_btn:  
(thumbnail clip).itemdetails\_btn.onRelease = ShowItemDetails;

The ShowItemDetails function is defined as follows:[/SIZE]

```
 ActionScript Code:
 [FONT=Courier New][LEFT][COLOR=#000000] **function** [/COLOR] ShowItemDetails[COLOR=#000000]([/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]
itemdetails_mc.[COLOR=#0000ff]visible[/COLOR] = [COLOR=#000000] **true** [/COLOR]; [COLOR=#808080]*//set to "false" at beginning*[/COLOR]
[COLOR=#000000] **var** [/COLOR] detailthumb = [COLOR=#0000ff]this[/COLOR].[COLOR=#000080]filepath_text[/COLOR];
itemdetails_mc.[COLOR=#000080]detailthumb_mc[/COLOR].[COLOR=#0000ff]loadMovie[/COLOR][COLOR=#000000]([/COLOR]detailthumb[COLOR=#000000])[/COLOR];

```

[COLOR=#000000]}[/COLOR]  
[/LEFT]  
[/FONT]

[SIZE=1]The first time the ShowItemDetails function is called:  
The full-size image is recentered and resized properly and the watermark is properly displayed.

Each successive time the function is called, while itemdetails\_mc is visible:  
Clicking on a thumbnail resizes the new loaded full-size image properly but doesn’t process the code to recenter: it just uses the same x and \_y coords as the first recentered image. The dimensions and coords of the watermark are also the same as the first.

My resize/recenter code:[/SIZE]  
ActionScript Code:  
[FONT=Courier New][LEFT][COLOR=#808080]_//after full size image loads into detailthumb\_mc,_[/COLOR]  
[COLOR=#808080]_//resize image so that neither width nor height is \> 150, tben recenter_[/COLOR]  
[COLOR=#0000ff]onClipEvent[/COLOR]COLOR=#000000[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] maxWidth = [COLOR=#000080]150[/COLOR];  
[COLOR=#000000] **var** [/COLOR] maxHeight = [COLOR=#000080]150[/COLOR];  
[COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_width[/COLOR] \> maxWidth || [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_height[/COLOR] \> maxHeight[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#000000] **var** [/COLOR] scaleFactor = [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_width[/COLOR] \> [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_height[/COLOR] ? maxWidth / [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_width[/COLOR] : maxHeight / [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_height[/COLOR];  
[COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_width[/COLOR] = [COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]floor[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_width[/COLOR] \* scaleFactor[COLOR=#000000])[/COLOR];  
[COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_height[/COLOR] = [COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]floor[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_height[/COLOR] \* scaleFactor[COLOR=#000000])[/COLOR];  
[COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_x[/COLOR] = [COLOR=#000080]85[/COLOR] - COLOR=#000000[/COLOR];  
[COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_y[/COLOR] = [COLOR=#000080]90[/COLOR] - COLOR=#000000[/COLOR];  
[COLOR=#808080]_//display gallerywm\_mc at bottom of resized image_[/COLOR]  
[COLOR=#000000] **var** [/COLOR] gallerywm = [COLOR=#0000ff]\_parent[/COLOR].[COLOR=#000080]gallerywm\_mc[/COLOR];  
gallerywm.[COLOR=#0000ff]\_x[/COLOR] = [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_x[/COLOR];  
gallerywm.[COLOR=#0000ff]\_y[/COLOR] = [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_y[/COLOR] + [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_height[/COLOR] - [COLOR=#000080]20[/COLOR];  
gallerywm.[COLOR=#0000ff]\_width[/COLOR] = [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_width[/COLOR];  
gallerywm.[COLOR=#0000ff]\_height[/COLOR] = [COLOR=#0000ff]Math[/COLOR].[COLOR=#0000ff]floor[/COLOR] [COLOR=#000000]([/COLOR]gallerywm.[COLOR=#0000ff]\_height[/COLOR] \* [COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_width[/COLOR] /[COLOR=#000080]150[/COLOR][COLOR=#000000])[/COLOR];  
[COLOR=#808080]_//hide boundingbox\_mc if image is portrait orientation_[/COLOR]  
[COLOR=#0000ff]if[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#0000ff]this[/COLOR].[COLOR=#0000ff]\_height[/COLOR] == [COLOR=#000080]150[/COLOR][COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]  
[COLOR=#0000ff]\_parent[/COLOR].[COLOR=#000080]boundingbox\_mc[/COLOR].[COLOR=#0000ff]\_visible[/COLOR]= [COLOR=#000000] **false** [/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#808080]_//hide imagepreloader\_mc_[/COLOR]  
[COLOR=#0000ff]\_parent[/COLOR].[COLOR=#000080]imagepreload\_mc[/COLOR].[COLOR=#0000ff]\_visible[/COLOR]= [COLOR=#000000] **false** [/COLOR];  
[COLOR=#000000]}[/COLOR]  
[COLOR=#000000]}[/COLOR]  
[/LEFT]  
[/FONT]

[SIZE=1]OPTIONS:

1. “Reset” or “refresh” the function so it’s like the first time each time you click on a thumbnail?
2. Modify the resize/recenter code so it resets the variables each time?

I want to keep the itemdetails\_mc open while switching to another thumbnail.

Thanks.[/SIZE]
