# Att: geniuses .. please help me figure out why this code doesn't work

**URL:** <https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705>\
**Category:** Uncategorized\
**Created:** [March 27, 2003, 5:01pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705 "2003-03-27T17:01:09Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![shuga](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@shuga](https://forum.kirupa.com/u/shuga)\
**Post date:** [March 27, 2003, 5:01pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/1 "2003-03-27T17:01:09Z")

</div>

this code is on a frame inside an MC i have and it performs the loadMovie fine as well as the preloader but when i try to apply an onPress function to the container clip with the loaded movie (jpg) in it … it doesn’t work. the lil hand doesn’t come up and the actions in the onPress script are not performed

any assistance is greatly appreciated

thanks

```php

this.createEmptyMovieClip("preloader", 1000);
this.createEmptyMovieClip("container", 1001);
     with (container) {
                loadMovie(_root.picture);
                _x = 225;
                _y = -46;
                _xscale = 25;
                _yscale = 25;
                _visible = false;
        }

preloader.onEnterFrame = function() {
    var l = container.getBytesLoaded();
    var t = container.getBytesTotal();
    var getPercent = l/t;
    loadText = Math.round(getPercent*100)+"%";
    loadBar._width = getPercent*160.5;
    if (l>0 && l>=t) {
        container._visible = 1;
		delete loadText;
		loadBar._visible = 0;
        delete this.onEnterFrame;
    }
}

MovieClip.prototype.scale = function(finX, finY) {
	this.speed = 5;
	this.endX = finX;
	this.endY = finY;
	this.onEnterFrame = function() {
		this._xscale += (this.endX-this._xscale)/this.speed;
		this._yscale += (this.endY-this._yscale)/this.speed;
	}
}

container.onPress = function() {
	if (_root.picsize == 0) {
		scale(25, 25);
		_root.picsize = 1;
	} else if (_root.picsize == 1) {
		scale(100, 100);
		_root.picsize = 0;
	}
}

```

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 5:30pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/2 "2003-03-27T17:30:56Z")

</div>

you need to assign the onPress handler once the movie/jpg is loaded

try this:

```auto
this.createEmptyMovieClip("preloader", 1000);
this.createEmptyMovieClip("container", 1001);
with (container) {
loadMovie(_root.picture);
_x = 225;
_y = -46;
_xscale = 25;
_yscale = 25;
_visible = false;
}
preloader.onEnterFrame = function() {
var l = container.getBytesLoaded();
var t = container.getBytesTotal();
var getPercent = l/t;
loadText = Math.round(getPercent*100)+"%";
loadBar._width = getPercent*160.5;
if (l>0 && l>=t) {
container._visible = 1;
delete loadText;
loadBar._visible = 0;
container.onPress = function() {
if (_root.picsize == 0) {
scale(25, 25);
_root.picsize = 1;
} else if (_root.picsize == 1) {
scale(100, 100);
_root.picsize = 0;
}
}
delete this.onEnterFrame;
}
}
MovieClip.prototype.scale = function(finX, finY) {
this.speed = 5;
this.endX = finX;
this.endY = finY;
this.onEnterFrame = function() {
this._xscale += (this.endX-this._xscale)/this.speed;
this._yscale += (this.endY-this._yscale)/this.speed;
}
}

```

=)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 5:33pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/3 "2003-03-27T17:33:51Z")

</div>

sweet … it works … now i just gotta edit the function b/c it’s all funky

thank you very much =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 5:35pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/4 "2003-03-27T17:35:27Z")

</div>

😛

anytime **shuga** =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 5:43pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/5 "2003-03-27T17:43:11Z")

</div>

_sniffle_ i can’t figure out how to get the jpg to scale without everything else

[http://www.aaronsleeper.com](http://www.aaronsleeper.com) \> enter the site \> click on the button that says tech \> click the first button on the left … a pic of flowers will pop up in the bottom right \> click that pic and see everything scale

i just want the picture to scale

[http://www.aaronsleeper.com/site.fla](http://www.aaronsleeper.com/site.fla)

the path to where all this is going on in the fla file is \_root.window.content.techtext (images layer, frame 2)

thanks for your help

--------------edit------------------  
ps. i want the image to scale larger … not smaller

and i’m trying to figure out how to get it to move and scale so it doesn’t go out of the screen when it scales larger =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 5:55pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/6 "2003-03-27T17:55:45Z")

</div>

```auto
container.onPress = function() {
if (_root.picsize == 0) {
this.scale(25, 25);
_root.picsize = 1;
} else if (_root.picsize == 1) {
this.scale(100, 100);
_root.picsize = 0;
}
}

```

😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 6:03pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/7 "2003-03-27T18:03:10Z")

</div>

Try replacing the onPress with this…

[AS]container.onPress = function() {  
if (\_root.picsize == 0) {  
this.scale(25, 25);  
\_root.picsize = 1;  
} else if (\_root.picsize == 1) {  
this.scale(100, 100);  
\_root.picsize = 0;  
}  
};[/AS]

Notice scale(25,25) was changed to \<B\>this.\</B\>scale(25, 25); same with the scale(100,100).

Otherwise it scales the clip it is in, which is the techtext, but when you define that \<B\>this\</B\> clip should run the scale function, it scales the container clip.

Please note though, then when you load an image into Flash, it connects the upper left corner to the movie clip, so this means it scales from that corner :-\

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 6:03pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/8 "2003-03-27T18:03:53Z")

</div>

Haha, you replied while I was typing kax. Shame on you.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 6:04pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/9 "2003-03-27T18:04:09Z")

</div>

you’re so slow my friend… 😛 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 6:07pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/10 "2003-03-27T18:07:12Z")

</div>

wow … that’s sweet … alright … so all my loaded jpgs are going to be the same size … so i’d like to figure out how i can move the MC on press along with the scale … so it appears to scale from the bottom right corner … i can find the exact numbers … i just can’t figure out how to add movement to the scaling function

thanks very much for all your help guys =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 6:09pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/11 "2003-03-27T18:09:57Z")

</div>

> \*Originally posted by kax \*  
> \*\*you’re so slow my friend… 😛 😉 \*\*

Sorry for explaining why I did what I did.

Sen stealer 😱

HAHAHA… 😛

I gotta go now, feel free to solve the next problem with the ease that I won’t be rushing to get there before you.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 6:11pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/12 "2003-03-27T18:11:59Z")

</div>

> _Originally posted by lostinbeta_  
> \*_Please note though, then when you load an image into Flash, it connects the upper left corner to the movie clip, so this means it scales from that corner :-\*_

true… but doesn’t mean you can’t keep the centre of the jpg at certain position 😉

**ie.** if you want to keep the centre at 100,100. you’d need to do something like this:

```auto
this._x = 100-(this._width/2);
this._y = 100-(this._height/2);

```

=)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 6:13pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/13 "2003-03-27T18:13:07Z")

</div>

here’s the script so you don’t have to go search through the code for it =)

```php

MovieClip.prototype.scale = function(finX, finY) {
        this.speed = 5;
        this.endX = finX;
        this.endY = finY;
        this.onEnterFrame = function() {
                this._xscale += (this.endX-this._xscale)/this.speed;
                this._yscale += (this.endY-this._yscale)/this.speed;
        }
}

```

ps. the center is ok to move it’s the bottom right corner that i want to stay stationary

b/c the pic is loaded in the bottom right corner of the movie and i want it to scale larger so that it appears to be getting bigger towards the upper left corner

🙂

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 6:16pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/14 "2003-03-27T18:16:38Z")

</div>

ok… then just add this lines:

```auto
MovieClip.prototype.scale = function(finX, finY) {
this.speed = 5;
this.endX = finX;
this.endY = finY;
this.onEnterFrame = function() {
this._xscale += (this.endX-this._xscale)/this.speed;
this._yscale += (this.endY-this._yscale)/this.speed;
this._x = xcentre-(this._width/2);
this._y = ycentre-(this._height/2);
}
}

```

again… **xcentre** and **ycentre** would be the coordinates where the centre of the jpg should be positioned 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 6:17pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/15 "2003-03-27T18:17:47Z")

</div>

we should stop editing/posting while someone else is posting!! 😛 :crazy:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 6:24pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/16 "2003-03-27T18:24:28Z")

</div>

but the center is going to move since it is scaled fromt the bottom right towards the top left

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 6:27pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/17 "2003-03-27T18:27:32Z")

</div>

i just took out the /2 after the \_width and \_height

now it works but i have to figure out the proper coordinates =)

thanks again!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 6:33pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/18 "2003-03-27T18:33:05Z")

</div>

i knew how to do that… i was giving you some time to think 😛 😉  
… i’m serious =)

and you want the proper coordinates for the bottom right corner?  
you can get them adding the width/height to the x/y of the movie clip 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 6:34pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/19 "2003-03-27T18:34:04Z")

</div>

figured that out … [http://www.aaronsleeper.com](http://www.aaronsleeper.com) … it works! =)

_tear_ thank you so much … you fuzzy lil geniuses you

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [March 27, 2003, 6:37pm UTC](https://forum.kirupa.com/t/att-geniuses-please-help-me-figure-out-why-this-code-doesnt-work/16705/20 "2003-03-27T18:37:33Z")

</div>

no problem man =)

and now that everthing is solved… i should get back to work :sure: 😛
