Movieclip onRelease
Hi everyone
my problim is:
I change my cursor with othe movielip and i want, when i
rollOver to movieclip wich one has function release, my cursors's
movieclip make something.
How to catch wich movieclip has onRelease function?
Thanks
if you wanted to add this function to all MCs you could do
something like that, maybe, not sure if you can prototype an 'on'
handler. But doing it with a prototype you would still need to add
the prototype call to each MC/button. However, if all the
MC/buttons are within another MC you could do something like this
(where MC is the name of the 'master' container):
for(var name in MC) {
if(typeof (MC[name]) == 'movieclip') {
MC[name].onRollOver = function() {
//the cursor change code here and other functions
you can use 'this' instead of 'MC' but it would apply to all
MCs throughout the doc.
Similar Messages
-
Hi all,
I'm new to Flash and I'm new to OOP, and so I'm having a bit
of trouble writing ActionScript programs to do exactly what I want.
I am trying to create a simple application, in which a
MovieClip is dragged around the screen and a textbox gets updated
with the MovieClip's coordinates somewhere else on the screen. I
wanted to do this using custom classes, so I created a class called
MovieClipCoordinates that would contain a MovieClip and a
TextField. I am initializing the MovieClip as the output of a
this.createEmptyMovieClip() of the main movie, and the TextField
similarly.
My intention is to have the TextField updated whenever the
MovieClip is dragged. So, in the onRelease function of the
MovieClip, I need to update the TextField of the
MovieClipCoordinates object that the MovieClip is a property of.
The problem is, I have no idea how to find out the
MovieClipCoordinates that the MovieClip belongs to. I thought I
would create a method in the MovieClipCoordinates class that would
set the TextField, which would be called from the
MovieClip.onRelease. So I figured I would not have a MovieClip
inside the MovieClipCoordinates class, but instead another class
inherited from MovieClip which also contains a reference to the
MovieClipCoordinates class that it is a member of. However, the
problem now is that I can no longer create this subclass through a
call to createEmptyMovieClip. So how do I create it?
I'm getting a bit confused at this point of time. Could
someone please give me some idea of how to do this?
Thanks.
AjitLuigiL,
Thank you very much for your assistance. I truly appreciate
it.
Though the code works perfectly, I wonder if I may trouble
you to clarify a couple of questions that I have with your code.
Looking particularly at this section of the code:
private function setHandlers(target_mc:MovieClip):Void{
//use a reference to the current object
var thisObj:MovieClipCoordinates=this;
target_mc.onPress=function():Void{
this.startDrag();
target_mc.onRelease=function():Void{
this.stopDrag();
//get the new coordinates
var thisX=thisObj.box_mc._x;
var thisY=thisObj.box_mc._y;
//and refresh the text
thisObj.printCoordinates(thisX,thisY);
How is it legal to use thisObj inside the onRelease function?
I was under the impression that the onRelease function is a
separate function altogether, that is called in the context of the
MovieClip that it is associated with. How does it have knowledge of
thisObj, which was defined in scope above it?
Would it be even possible to define the onPress and onRelease
functions above as two separate functions (CoordinatesPress and
CoordinatesRelease, for example) and rewrite the above code as
follows?:
private function setHandlers(target_mc:MovieClip):Void{
//use a reference to the current object
var thisObj:MovieClipCoordinates=this;
target_mc.onPress=CoordinatesPress;
target_mc.onRelease=CoordinatesRelease;
defining the handler functions separately. If I chose to do
this, how would I possibly pass the thisObj to the handlers?
I seem to be missing something fundamental in ActionScript
functions, or perhaps just in the event-handlers. I would
appreciate it if you could help me clear this up.
Thanks again,
Ajit -
Hello,
currently I'm working on a draggable movieclip and in it I
have a button that is supposed to open a new window. The movieclip
is tweended and follows a path (circles). The button moves along
with the movieclip because it is contained in a graphic.
The button is part of the graphic that is in the movieclip so
basicly this is the way it is build up:
movieclip (draggable) / graphic / button (should be clickable
but it doesn't work)
So far I got this script (which works on the movieclip) but
as you can understand I want the last part to work only on the
button.
quote:
on(press) {
startDrag(this);
on(release) {
stopDrag();
on (release) {
getURL ("javascript:
openNewWindow('pop.html','myWin','width=500,height=300,toolbar=no')");
I'm using Flash MX 2004.
Thanks for your help.iConvict,
> movieclip (draggable) / graphic / button (should be
clickable
> but it doesn't work)
Draggable buttons are something of a problem. You have a
button inside
a movie clip, and the movie clip has dragging capabilities.
That means the
movie clip is already "listening" for mouse events, and since
the movie clip
is your outermost object, it obscures objects inside it that
also listen for
mouse events. Make sense?
> So far I got this script (which works on the movieclip)
but as
> you can understand I want the last part to work only on
the
> button.
>
> on(press) {
> startDrag(this);
> }
Okay, so this part (above) is on your movie clip.
> on (release) {
> getURL ("javascript:
>
openNewWindow('pop.html','myWin','width=500,height=300,toolbar=no')");
> }
And this part (above) is also on your movie clip. Which
means you
you're not handling the button's events at all. Just about
everything in
ActionScript is an object, and objects are defined by their
namesake
classes. You can look up the Button class, for example, and
find out all
the properties, methods, and events of a button symbol. Same
for the
MovieClip class, TextField class, and so on. Properties are
characteristics
the object has, methods are things the object can do, and
events are things
the object can react to.
But even if you properly wrote instructions for the button's
events
(versus the movie clip's events), the movie clip's existing
mouse event
handlers would "obscure" those of the button.
So one approach -- there are, perhaps, others -- is to use
the
MovieClip.hitTest() method to determine if the button is
"hitting" a
particular point, then handling that -- all from the movie
clip's point of
view. In order to use MovieClip.hitTest(), that button will
have to be a
movie clip, since the Button class does not feature a
hitTest() method.
NOTE: I'm using a different approach from the on() event
handler. on()
and onClipEvent() still work, of course, but they represent
the way things
were done back in Flash 5. Since Flash MX (aka Flash 6), it's
been possible
to assign event handlers using dot syntax. I prefer that way
because it
means I can put all my ActionScript in one place (a frame of
the main
timeline) rather than dispursed among various symbols.
So ... that said, here's what you need in order to test my
suggestion.
Start a new FLA -- this just keeps things clean -- and draw a
rectangle.
Convert that to a movie clip. Inside that movie clip, draw a
circle and
convert that to a movie clip, too. This inner circle movie
clip is going to
be your "button". Select it and look at the Property
inspector. You'll see
where you can give this "button" an instance name. Instance
names are
different from the names you give something in the Library.
These are
unique identifiers to a given instance of your object on the
Stage. For
now, name this thing mcButton. Step out of the timeline
you're in (the
outer movie clip's timeline) in order to be able to give the
outer movie
clip an instance name, too. For now, name the outer clip
mcClip.
Now, the code.
mcClip.onPress = function() {
if (!this.mcButton.hitTest(_root._xmouse, _root._ymouse,
true)) {
this.startDrag();
mcClip.onRelease = function() {
this.stopDrag();
if (this.mcButton.hitTest(_root._xmouse, _root._ymouse,
true)) {
trace("button click");
So, what's going on, here? According to the MovieClip class,
all movie
clips feature a MovieClip.onPress event. We're assigning a
function to this
event and instructing the outer clip to start dragging (the
MovieClip.startDrag() method) if the mouse position is NOT
colliding with
the inner "button" clip.
MovieClip.hitTest() can be used two ways: a) am I colliding
with
another clip? OR b) am I colliding with a certain point?
We're using the
second way here. The exclamation point at the beginning makes
this a
negation ... a NOT question. Hold that thought. Next, the
global "this"
property refers back to whatever timeline or object we're in.
Since we're
scoped to a function that is assigned to the onPress event of
mcClip, the
word "this" refers to mcClip in this context. Therefore,
this.mcButton
refers to the mcButton instance inside of mcClip. Our path,
then
(this.mcButton), leads us to the "button" clip, which is a
MovieClip
instance. Since it is, it has the MovieClip.hitTest() method
available to
it. In the "second way" to use hitTest(), we supply three
parameters: a)
the mouse's horizontal position from the point of view of the
main
timeline -- this is the MovieClip._xmouse property -- b) the
mouse's
vertical position from the same POV, and c) a "true" value
that indicates
yes, we want to recognize the button's round shape, rather
than the
rectangle described by its bounding box.
When the mouse -- from the POV of the main timeline -- is
indeed inside
the boundaries of the mcButton clip, hitTest() will return
true. Since
we're negating that with out exclamation point, we're
actually looking for
cases where the mouse is NOT within the boundaries of the
mcButton clip.
That's what our if() statement checks for. When the mouse is
NOT within
mcButton, start dragging. This means that clicking inside the
outer
rectangle clip will allow dragging, but only when the
clicking is done
outside the button itself.
Next, when the user stops clicking -- the
MovieClip.onRelease event --
the clip should stop dragging, in all cases. Then, using the
same logic as
above, another if() statement checks of the mouse happens to
be inside the
boundaries of the inner clip. If it is -- because we're not
negating,
here -- then do something.
The above code should go in a keyframe of the main timeline,
where, from
that point of view, the mcClip object (identified by its
instance name) is
"visible."
This *can* be done using on(), so think through the
principles involved
and do it that way, if you prefer. If you use on(), you don't
need an
instance name for the outer clip, because your code is
directly attached
*to* that clip, so the indended recipient of your
instructions is clear.
But you will need an instance name for the inner clip in
order to reference
it from the outer one.
David
stiller (at) quip (dot) net
Dev essays:
http://www.quip.net/blog/
"Luck is the residue of good design." -
Where do I find anm experienced Action Scripted fast?
Hi,
I have a Flash presentation which needs completed. Basically,
all of the buttons need programmed and as a newbie who is running
out of time to learn, I need some help.
First, I'd like to know where you find people who can do this
(here?)
Secondly, how long it would take to programme approx 875
buttons (many of which are repetitions (e.g home button, help
button, exit button appearing on every screen). There are
approximately 109 screens which need to be linked.
Thirdly, what would be a realistic price to expect to pay for
someone to do this? It is a non-profitmaking project for a
voluntary organisation.
Thanksnicknamesaretaken,
> I think I see what the problem is, but still struggling
to
> get it to work.
Okay.
> I now have:
>
> stop(); {
> on (release)
> this.gotoAndPlay("CS1"); // this is the correct code.
> }
Okay, the on() event handler may not belong here. The on()
and
onClipEvent() functions are an older (Flash 5 era) way to
handle events in
ActionScript. They're still available in Flash 8, and they
work just fine,
even in AS2, but these are applied *directly to* the object
in question; as
in, you click your button to select it, then type into the
Actions panel
while the button is selected. In such a case, no instance
name is needed
for the button (or whatever object). The above code would
have to be
attached to each button -- which really gets old with a large
number of
buttons -- and the stop(); action would have ben appear
inside the on()
function.
Your earlier approach -- where you referenced the button's
instance name
and assign a function to the Button.onRelease event -- is the
recommended
best practice, and has been available since Flash MX (aka
Flash 6). There's
nothing about your earlier code that shouldn't have worked --
it's just you
*might* have been experiencing the Scenes-related bug I
mentioned.
I would change your previous code as follows:
// in a frame script ...
stop();
skipintro_btn.onRelease = function() {
this._parent.gotoAndStop("frame label here");
That stops the timeline in which this ActionScript appears.
Then it
assigns a function literal to the Button.onRelease event of
the button
symbol whose instance name is skipintro_btn (if that object
is actually a
movie clip, then it assigns a function literal to the
MovieClip.onRelease
event of that instance -- funtionally the same thing). Then
it refers to
the parent of this object, which is the timeline in which the
object
appears, and tells that timeline to gotoAndStop() at the
named frame label
you provide -- even if that frame label is in another scene.
Make sense?
> Are there any good Action Script books you could
> recommend?
There are quite a few good ones on the market lately, but
the last I can
think of that I enjoyed -- from a general programming
standpoint -- is
Object-Oriented ActionScript For Flash 8 (Friends of ED), by
Peter Elst and
Todd Yard.
> I'm also a bit worried about bug comment. Does it mean
> that I will have difficulty playing this project in
Flash Player
> 9 as it's not written in Action Script 3.0?
You shouldn't have any problems. As long as you use the
frame labels
approach and avoid Scene names, Flash Player 9 will run it
the same as older
Players. Flash Player 9 is the first to feature *two* virtual
machines for
ActionScript. One is the overhauled AS3-lovin' machine; the
other maintains
backward compatability for AS1 and AS2.
> If so, that's a big problem isn't it as people will need
to
> download older versions of Flash Player to view it - or
> I'll need to include older version on the disc.
Right, but you don't have to worry about that. :) The Scenes
issue is
an old one, and it is a big problem, but at least the
workaround is easy
(frame labels).
David Stiller
Adobe Community Expert
Dev blog,
http://www.quip.net/blog/
"Luck is the residue of good design." -
Unexpected Behaviour of flash event handling mechanism
I am implementing my own selection manager in flash. When
ever you have key down the mouse events for movieclips onRelease()
is called even though you have'nt yet released it. ( if any one
knows how to handle please replyDear Khedar Prasad,
Thank you so much for your wonderful suggestion.
I included your following suggestion at BSVW under system settings(system status events).
1. I0001: CRTD in create event which is the system status set when you create any project ( see basic data tab)
in this way the event created will get triggered only when you create any project.
My workflow now behaves as expected.
I am extremely thankful to you.
Thanks and regards,
S.Suresh -
I've recently been trying to wrap my head around the Listener
Object (which had always seemed confusing to me). Tutorials made
its workings clear, but what they don't seem to touch upon is the
WHY and WHEN of using it...
First, what I've read has said that "Your listener object can
be any object, such as an existing object, movie clip, or button
instance", but why would you want to use anything other than a
Listener Object? Would it make sense syntactically to take a movie
clip that you want to respond to a particular event , and add
handlers and "addListener" it to the broadcasting object, or is
there a reason that you would want to make a standalone Listener
Object?
Also, are Listener Objects only intended for certain classes,
such as MovieClipLoader, Selection, etc? Can a normal MovieClip be
a broadcaster too?
And what is the MovieClipLoader class specifically? Does it
"exist" on the stage, or is it just an intermediary that then uses
a MovieClip? Does it HAVE to be used with the listener object?
MovieClips have onLoad() and getBytesLoaded() functions as
well...couldn't these be used just as easily to load external
content?l_andrew_l,
> I've recently been trying to wrap my head around
> the Listener Object (which had always seemed
> confusing to me).
I hear ya. I don't know why, but when I first started using
listeners,
I always had to keep refreshing my memory by looking up the
syntax -- again
and again.
> Tutorials made its workings clear, but what they don't
> seem to touch upon is the WHY and WHEN of using it...
As for when, I believe it simply depends on the structure of
the object
whose events you wish to code against. Some objects are built
to need
handlers, some listeners -- and you find out which is which
by looking up
that object's entry in the ActionScript Language Reference.
Caveat: I
won't swear to this, because I was recently involved in a
post where someone
used listeners in a way that surprised me. He (I think he)
was using a
listener on an object that I had only seen used with
handlers.
> First, what I've read has said that "Your listener
> object can be any object, such as an existing
> object, movie clip, or button instance", but why
> would you want to use anything other than a
> Listener Object?
Odd. I've never heard that. I suppose it is *possible* to
use almost
any object as a listener. By and large, most objects in
ActionScript --
including movie clips, buttons, and so on -- inherit from the
generic Object
object. But personally, I would keep it clean and use a
generic Object
instance. Just be be clear, there is no ListenerObject class
in
ActionScript, or anything officially (exclusively) known as a
"Listener"
object. There is an Object class that instantiates generic
objects, and
that's what is typically used to create a "listener object."
> Would it make sense syntactically to take a movie clip
> that you want to respond to a particular event, and add
> handlers and "addListener" it to the broadcasting
object,
> or is there a reason that you would want to make a
> standalone Listener Object?
The MovieClip class does not feature an addListener()
method, so I'm a
bit confused by what you're saying, here. MovieClip events
only require
handlers. If you want to assign a function to the
MovieClip.onRelease
event, it's pretty straight forward ...
mcInstance.onRelease = function() {
// instructions here
So in this scenario, there is no reason to create a
stand-alone listener
object. After all, how would you subscribe your listener to a
given
MovieClip instance?
> Also, are Listener Objects only intended for certain
classes,
> such as MovieClipLoader, Selection, etc? Can a normal
> MovieClip be a broadcaster too?
Right, listeners are only for objects that need them, such
as
MovieClipLoader. Again, I believe this is simply due to the
way each class
is written. If I'm wrong, I hope someone will correct me on
this.
Anyway, use the search phrase "addListener method" (with
quotes) in the
Help panel to find the objects that require listeners.
Without that
addListener method, there's nothing with which to "marry" the
listener
object to its broadcaster. Make sense?
Can a normal MovieClip instance be a broadcaster, too? Sure.
The
MovieClip class is dynamic, which means you can add
properties to any
MovieClip instance. You could add properties to a movie clip
that cause it
to become an event broadcaster (see the AsBroadcaster class
in the
ActionScript Language Reference and the EventDispatcher class
in the
Components Language Reference).
> And what is the MovieClipLoader class specifically?
MovieClipLoader is a non-visual object (like an Array
instance, Date
instance, etc.) that loads external SWFs and other media.
> Does it "exist" on the stage, or is it just an
intermediary
> that then uses a MovieClip?
It doesn't use a MovieClip at all. It exists in memory, but
it isn't
visual, so I suppose it doesn't "exist on the Stage" in the
way that movie
clips, buttons, and text fields do.
> Does it HAVE to be used with the listener object?
I think so.
> MovieClips have onLoad() and getBytesLoaded()
> functions as well...couldn't these be used just as
easily
> to load external content?
Functions that belong to a given class, such as
MovieClip.getBytesLoaded(), are called methods. Just like
variables that
belong to a given class are called properties.
You can certainly use a combo of MovieClip.getBytesLoaded()
and
MovieClip.getBytesTotal() to determine when external content
has loaded. In
fact, this was the way it was done before MovieClipLoader
entered the
picture (back in Flash MX [aka Flash 6] and earlier).
Check out this recent blog entry of mine for details on this
older
approach to loading content.
http://www.quip.net/blog/2006/flash/how-to-tell-when-external-swf-loaded
And you may want to read my article on objects to get a
better feel for
how they're related to classes in ActionScript.
http://www.quip.net/blog/2006/flash/actionscript-20/ojects-building-blocks
Hope those help!
David
stiller (at) quip (dot) net
Dev essays:
http://www.quip.net/blog/
"Luck is the residue of good design." -
Can we make array of movieclip and use as onrelease function
var gold:Array = [g1,g2,g3,g4,g5,g6,g7,g8,g9,g10,g11,g12,g13,g14,g15,g16,g17,g18,g19,g20];
and
gold.onRelease=function(){
if(gold._visible==1){
this.gotoAndStop(2);
updateScore(500);
this.enabled=false;var gold:Array = [g1,g2,g3,g4,g5,g6,g7,g8,g9,g10,g11,g12,g13,g14,g15,g16,g17,g18,g19,g 20];
and
for(var i:Number=0;i<gold.length;i++){
gold[i].onRelease=function(){
// it's not clear what you want to do here for each element of gold. -
Passing a variable to set a movieclip location
In frame 1 of the the movie I have defined the following:
var cl_y=502.0;
Elsewhere, I am running the following script:
-- seaty is the original position of the movie clip as
defined in frame 1
var seaty = this+"_y";
-- resets the position of the movie clip to the original
position
this._y = seaty;
(note - I am just setting the _y position in this code in
order to simplify the forum post)
I expected that this._y = seaty; would reset the position of
the movie clip to the original position as defined in frame 1.
However, nothing happens.
I have used a trace () to discover the value of seaty:
Running trace(seaty) produces _level0.cl_y
Please note that trace(seaty) does not equal the value of
_level0.cl_y (which is what I am wanting to achieve)
I then tried replacing:
this._y = seaty;
with the following:
this._y = level0.cl_y;
And this produces the desired result (moving the movieclip to
the original position)
Even though seaty = level0.cl_y
why does this work:
this._y = level0.cl_y;
and yet this doesn't work:
this._y = seaty;
(I need it to work because I need to use the same function to
reset the position of numerous movieclips, all with different
original positions)
Many thanks in expectationPulcinella2uk, it tells me you have elected not to receive
private messages.....so i'll put my reply here for now....
what version of flash are you using? if you're using an old
version, something like this might work:
onClipEvent(load){
var seatx = this._x
var seaty = this._y
onClipEvent(mouseUp){ //or whichever event you're using
this._x = seatx
this._y = seaty
if you're using 7 or later though, then actionscript really
ought to go on a frame instead of on a clip. so the above code
would reside on frame 1 of your movie, and look like:
var seatx = this._x
var seaty = this._y
onRelease = function(){ //or whichever event you're using
this._x = seatx
this._y = seaty
all that aside, if i understand your last question correctly,
you're looking to establish these variables on the _root timeline,
and access them later. the second code snippet above will produce
the same result, but if you ever do want to access a variable based
on a movieclips name in this way, you could do it like this:
on frame 1of _root timeline:
var c1_x=15;
var c1_y=502.0;
on frame 1 of clip:
this._x = _root[this._name+"_x"]
this._y = _root[this._name+"_y"]
i hope that all made sense. let me know, and if you need to,
send me a copy of your file so that i have a btter idea of what
you're trying to accomplish -
Change Movieclips Parameters-Variables
Hi,
Im working on the following code and i need some help to
change part of the code:
The code is a slider to view pictures loaded from external
file. I changed the size of the stage(1000x1000), the big pictures
are displayed above(1000x400) and i would like to do 3 things:
1.The slider has the size(400x50). I changed its
size(500x80), the thumbnails move but at some point the slider
remains half empty and then fills up again. This happens when i
have small amount of pictures. I would like not to double but
treble the No of the thumbnails so the slider wont remains empty.
2.Move the thumbnails on the right-half part of the stage.
When i only change the coordinates(x,y) of the slider it doesnt
work.They r loaded on the right part, but when placing the cursor
above they disappear.
3.Is it possible when placing the cursor over a thumbnails to
show text(small description of each pic)????
Heres the URL of the code working:
http://www.flash-creations.com/notes/dynamic_slidingviewer.php
Thanks
Theo
Heres the code:
/********* DECLARE AND INITIALIZE VARIABLES
// names of folder and pictures, in the order to put them
into the slider
var picnames:Array = [
"flower_orange",
"flower_yellow",
"flower_pink",
"flower_red",
"flower_purple"
// constants
var PICPATH:String = "flowers/"; // folder with jpgs
var NPICS:Number = picnames.length; // number of pictures to
load
var PICX:Number = 10; // x loc of big picture
var PICY:Number = 10; // y loc
var THUMBHOLDERX:Number = 0; // x location of thumbnail
holder movieclip
var THUMBHOLDERY:Number = 240; // y location
var THUMBW:Number = 72; // width of each thumbnail
var THUMBH:Number = 40; // height
var MARGIN:Number = 10; // margin between thumbnails
var TOTALBYTES:Number = 212000; // approx sum of bytes in all
jpgs (x 2)
var MAXPIXELS:Number = 12; // max number of pixels to move
slider per frame
// mask definition; mask is assumed to cover some part of the
thumbnail slider (here the numbers
// were chosen so that there are margins between the mask and
the right and left edges of the movie
// (which is 420 x 290), and enough space above and below the
thumbs to show them when they 'grow'
// on mouseover
var MASKX:Number = 10; // start x location of mask
var MASKW:Number = 400; // mask width
var MASKY:Number = 230; // start y location of mask
var MASKH:Number = 60; // mask height
var totalloaded:Number = 0; // running tally of bytes loaded
from all pics
// index into pictures array, used for loading
var ipic:Number;
// set up loader, an instance of MovieClipLoader
var loader:MovieClipLoader = new MovieClipLoader();
// use the main timeline to listen to and respond to loader's
broadcast events
loader.addListener(this);
/********* DEFINE FUNCTIONS, INCLUDING INIT FOR MOVIE SETUP
// thumbnail rollover handler
function grow() {
this.onEnterFrame = function() {
if (this._width < THUMBW * 1.2) {
this._x -= this._width * .025;
this._y -= this._height * .025;
this._width *= 1.05;
this._height *= 1.05;
} else delete this.onEnterFrame;
// thumbnail rollout handler
function shrink() {
this.onEnterFrame = function() {
if (this._width > THUMBW) {
this._width /= 1.05;
this._height /= 1.05;
this._x += this._width * .025;
this._y += this._height * .025;
} else delete this.onEnterFrame;
// function to move thumbnail slider ("this" = thumbs_mc)
function sliderControl() {
var w:Number = this._width/2;
var hw:Number = mask_mc._width/2;
var npixels:Number;
// only do when mouse over slider mask
if (_ymouse > mask_mc._y && _ymouse <
mask_mc._y + mask_mc._height) {
// mouse over left half of slider:
if (_xmouse > mask_mc._x && _xmouse <
mask_mc._x + hw) {
npixels = (hw - _xmouse) / hw * MAXPIXELS;
this._x += npixels;
if (this._x >= 0) this._x = this._x - w;
// mouse over right half of slider:
} else if (_xmouse > mask_mc._x + hw && _xmouse
< mask_mc._x + mask_mc._width) {
npixels = (_xmouse - hw) / hw * MAXPIXELS;
this._x -= npixels;
if (this._x <= -w) this._x = this._x + w;
// thumbnail click (onrelease) handler
function openPic() {
pic_mc.loadMovie(PICPATH + picnames[this.i] + ".jpg");
// assign event handlers (called when all jpgs are loaded)
function setupHandlers() {
pct_txt.removeTextField(); // don't need loading indicator
any more
thumbs_mc.onEnterFrame = sliderControl;
for (var i:Number = 0; i < NPICS*2; i++) {
thumbs_mc["mc"+i].onRollOver = grow;
thumbs_mc["mc"+i].onRollOut = shrink;
thumbs_mc["mc"+i].onRelease = openPic;
// listener function for broadcast 'done' message (for each
pic)
// onLoadInit gets executed when the movieclip has been
loaded into _mc AND
// its width and height data are available.
// (_mc = the movieclip being loaded into)
// this routine sets the size and position of each thumbnail
clip as its jpg
// is loaded and starts the next one loading. When all have
been loaded,
// a random picture is loaded into pic_mc and setupHandlers
is called to
// assign handlers to each thumbnail movieclip
function onLoadInit(_mc:MovieClip) {
// this gets done when the jpg is completely loaded:
_mc._width = THUMBW;
_mc._height = THUMBH;
_mc._alpha = 99; // for image clarity
// give the movieclip a property to remind it who it is
// (used by openPic to know which big picture to open)
_mc.i = (ipic >= NPICS ? ipic-NPICS : ipic);
// add picture size to totalloaded variable
totalloaded += loader.getProgress(_mc).bytesTotal;
// now load the next one (if there are more) or set up
handlers if done
ipic++;
if (ipic == NPICS * 2) {
// start with a random photo displayed when all thumbs
loaded
pic_mc.loadMovie(PICPATH +
picnames[Math.floor(Math.random()*NPICS)] + ".jpg");
setupHandlers();
} else if (ipic >= NPICS) {
// load jpg into duplicate thumbnail (will already be
cached)
loader.loadClip(PICPATH + picnames[ipic-NPICS] + ".jpg",
thumbs_mc["mc"+ipic]);
} else {
// load jpg into thumbnail
loader.loadClip(PICPATH + picnames[ipic] + ".jpg",
thumbs_mc["mc"+ipic]);
// listener function to handle broadcast progress messages
// make pct_txt show cumulative loading progress
function onLoadProgress(_mc:MovieClip, loaded:Number) {
var loadedsofar:Number = totalloaded + loaded;
pct_txt.text = Math.floor(loadedsofar / TOTALBYTES * 100) +
function init() {
// create holder for pictures
createEmptyMovieClip("pic_mc", 1);
pic_mc._x = PICX;
pic_mc._y = PICY;
// create (and draw) holder for thumbnails
createEmptyMovieClip("thumbs_mc", 2);
thumbs_mc.beginFill(0, 100); // black
thumbs_mc.moveTo(0, 0);
thumbs_mc.lineTo(2 * (MARGIN + THUMBW) * NPICS, 0);
thumbs_mc.lineTo(2 * (MARGIN + THUMBW) * NPICS, THUMBH);
thumbs_mc.lineTo(0, THUMBH);
thumbs_mc.endFill();
// drawing the thumb holder at 0, 0 and then moving it makes
its reg point = upper left
thumbs_mc._x = THUMBHOLDERX;
thumbs_mc._y = THUMBHOLDERY;
// create, draw and enable mask over thumbs (could use
different variables to define mask
// if desired)
createEmptyMovieClip("mask_mc", 3);
mask_mc.beginFill(0x0000cc, 100);
mask_mc.moveTo(0, 0);
mask_mc.lineTo(MASKW, 0);
mask_mc.lineTo(MASKW, MASKH);
mask_mc.lineTo(0, MASKH);
mask_mc.endFill();
mask_mc._x = MASKX;
mask_mc._y = MASKY;
thumbs_mc.setMask(mask_mc);
// create loading textfield indicator
createTextField("pct_txt", 4, 200, 100, 40, 100);
var tf:TextFormat = new TextFormat();
tf.align = "center";
tf.size = 12;
tf.font = "Verdana";
tf.color = 0xFFFF00;
pct_txt.setNewTextFormat(tf);
// make empty movieclips in thumbs_mc for each pic to go
into
// make double the number so the slider can move
continuously and show content
for (var i:Number = 0; i < NPICS * 2; i++) {
var mc:MovieClip = thumbs_mc.createEmptyMovieClip("mc"+i,
i+1);
mc._x = i*(MARGIN + THUMBW);
mc._y = 0;
// set the pointer to the first jpg in the array picnames
ipic = 0;
// start loading jpgs (ipic is initialized to 0)
loader.loadClip(PICPATH + picnames[ipic] + ".jpg",
thumbs_mc["mc"+ipic]);
/********* CALL THE INIT FUNCTION TO START THE MOVIE
init();Hi,
Thanks for the quick reply.
The problem here is there variables are again used in calculating some other variable values either single value or intervals. Also there are many queries which use these variable I am discussing about. So, in this case it will be really hectic to change all these queries. Even though if we change these variable properties, I think as these are mandatory customer exit default value variables, there wont be any effect. If at all any exists can you please let me know what type?
What do you suggest?
Regards,
Ravi -
Play a frame in timeline from inside 2 movieclips.
Hi. I have tried everything but it just isn't working.
On my main timeline I have a MC called "rainbow." Inside "rainbow" I have a MC called "greenbow."
Inside "greenbow" I have a MC called "meetbtn2"
I want it to play frame 134 on the main timeline when you click "meetbtn2."
my code inside greenbow is as follows:
meetbtn2.onRelease = function () {
_root.gotoAndPlay(134);
however it doesn't work! is it because i am inside two MC's?
I have also tried
_root.rainbow.greenbow.meetbtn2.onRelease = function () {
_root.gotoAndPlay(134);
any help? Thanks!i believe you miss understood me. the actionscript and the MC are on the same frame on the same timeline.
however
on the main timeline: the MC "rainbow" doesn't appear til frame103
inside "rainbow": the MC "greenbow" doesn't appear til frame 48
inside "greenbow": the movieclip that acts as the button"meetbtn2" doesn't appear til frame 11
however all instances have been named correctly and all actionscript is on the same frame-space as its objects.... -
Centering different size images in movieclip
Hi,
I'm trying to center different size images in a movieclip
named "picture". The images load fine but they are not centered.
Flash's registration is very limited when it comes to setting this.
All the images are different sizes. I may get one to load correctly
but when another image loads of a different size the images is no
longer centered. I need all images to load in the center of the
clip no matter what the images size is. Here is the code that I'm
using:
stop();
function loadXML(loaded) {
if (loaded) {
xmlNode = this.firstChild;
image = [];
description = [];
total = xmlNode.childNodes.length;
for (i=0; i<total; i++) {
image
= xmlNode.childNodes.childNodes[0].firstChild.nodeValue;
description
= xmlNode.childNodes.childNodes[1].firstChild.nodeValue;
firstImage();
} else {
content = "file not loaded!";
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;
xmlData.load("images-webbanner.xml");
listen = new Object();
listen.onKeyDown = function() {
if (Key.getCode() == Key.LEFT) {
prevImage();
} else if (Key.getCode() == Key.RIGHT) {
nextImage();
Key.addListener(listen);
previous_btn.onRelease = function() {
prevImage();
next_btn.onRelease = function() {
nextImage();
p = 0;
this.onEnterFrame = function() {
filesize = picture.getBytesTotal();
loaded = picture.getBytesLoaded();
preloader._visible = true;
if (loaded != filesize) {
preloader.preload_bar._xscale = 100*loaded/filesize;
} else {
preloader._visible = false;
if (picture._alpha<100) {
picture._alpha += 10;
function nextImage() {
if (p<(total-1)) {
p++;
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
picture_num();
function prevImage() {
if (p>0) {
p--;
picture._alpha = 0;
picture.loadMovie(image[p], 1);
desc_txt.text = description[p];
picture_num();
function firstImage() {
if (loaded == filesize) {
picture._alpha = 0;
picture.loadMovie(image[0], 1);
desc_txt.text = description[0];
picture_num();
function picture_num() {
current_pos = p+1;
pos_txt.text = current_pos+" / "+total;
}A very simple solution is to make a second image that contains the picture superimposed on the map. You would need to have 4 images total for this (all images are the same size):
1. The map with no photos
2 - 4. The map with a single image over the desired region (i.e., 3 additional images).
In your hotspots, you swap the entire map with the desired region map. -
Questions about buttons: onRelease and on(release)
I have been experimenting with buttons lately and am trying to use a function that uses the release mouse event. I was a little confused at first, since I found some tutorials that used onRelease() and some that used on(release) {...can somebody explain the differences to these and how to use either of them?
if you're using as2, both onRelease and on(release) can be used. on(release) is attached to the button or movieclip (highly undesirable) and onRelease is attached to a frame using the button/movieclip's instance name:
// if your objects instance name is your_btn:
your_btn.onRelease=function(){
// code here
if you're using as3, neither will work. -
Moving 2 different movieClips at same time onPress function
Hello,
Im using the following code to simulate a volume control bar filling on vol+ and unfilling on vol-.
The dragger is a mask that causes the fill to appear and dissappear when the mouse is pressed and dragged on the volume controller.
It works well, but i would like to add a "switch" that moves at the same time and in the same location as the fill, but on top of it... I created the movieClip for the switch and tried all kinds of variations to the following code with its instance in the code, but cant seem to get it working... below is the code which works with just the mask filling / unfilling.
Any help would be great!
this.ratio = 0;
dragger.onPress = function() {
this.startDrag(true, 0, 0, line._width, 0);
this.onEnterFrame = function() {
ratio = Math.round(this._x*100/line._width);
_root.volume = ratio;
dragger.onRelease = dragger.onRelease=stopDrag;
Thanks!
Patuse:
this.ratio = 0;
dragger.onPress = function() {
this.startDrag(true, 0, 0, line._width, 0);
this.onEnterFrame = function() {
switch_mc._x=this._x;
ratio = Math.round(this._x*100/line._width);
_root.volume = ratio;
dragger.onRelease = dragger.onRelease=stopDragF;
function stopDragF(){
this.stopDrag();
delete this.onEnterFrame; -
Detecting Click on an MC inside an attached movieclip
I'm working with a MovieClip ("mainMenuItem") that is linked to a Class ("GenericMenuItem.as") that uses attachMovie to add another movieclip ("Arrow") to mainMenuItem as follows:
mcArrow = this.attachMovie(prefix+"Arrow", "_Arrow_symbol", this.getNextHighestDepth());
I'm able to use on(release) within the Class definition to capture clicks on the mainMenuItem component, but haven't been able to find a way to detect a click on the "Arrow" library item that gets attached to that component.
Any thoughts?Thanks...GenericMenuItem (the class linked to mainMenuItem, which itself doesn't have any code) doesn't have any on(release) actions inside it now. I've tried creating a separate Arrow.as class and linking it to that Arrow MovieClip symbol. I'm able to trace output inside the constructor for the Arrow class, but haven't had any luck creating an onPress/onRelease function that works there (I've tried a "this.onPress = Delegate.create(this,function()..." in the constructor, and a "public function onRelease()" in the class body without any luck in either case. I also tried adding "mcArrow.onRelease = function()" below instantiation for mcArrow in the GenericMenuItem.as class, where this is attached (ensuring that the onRelease action occurs in either the Arrow.as class or the GenericMenuItem.as, but not in both places simultaneously, to avoid conflicts). In all cases, I haven't been able to trace anything out on a click action, so don't believe it is handling clicks for this.
I'd be happy to send over project files if you'd like to take a look. Getting some pressure from a client to get this working, so any help you can provide would be immensely appreciated.
Any thoughts? -
Movie clips inside an animated movieclip
Hello- I have been trying to get movieclip buttons inside an
action script animated movie clip to work and have no luck doing
so. The inside movieclips act as if they dont have over or out
states; but when i comment out the animation, they work fine...
here is my code- (Please note im am a newbe at action script so any
suggestions on improving current code will be greatly appreciated)
stop();
import mx.transitions.Tween;
import mx.transitions.easing.*;
function upFunction() {
var xPosT:Tween = new Tween(kText, "_x", Strong.easeOut,
kText._x, 400, 1, true);
function downFunction() {
var xPosT:Tween = new Tween(kText, "_x", Strong.easeOut,
kText._x, 200, 1, true);
kText.btn.onRelease = function():Void {
_root.play();
kText.onRollOver = function():Void {
upFunction();
kText.useHandCursor = false;
kText.onRollOut = function():Void {
downFunction();
kText is the animated movieclip, btn is the button inside
kText
Thanks!if you define any mouse handlers for a parent movieclip (like
kText) it will intercept all mouse events so child movieclips (like
kText.btn) do not see the mouse events.
to remedy define all mouse handlers for shapes (converted to
movieclips), buttons and movieclips on kText's timeline or use a
loop with hitTest one the parent or child
Maybe you are looking for
-
Apple TV - iTunes Store Password
My Apple TV continues to request my password, even though it's correct. What do do?
-
Win 7, .flv file association to Flash player
I lost the association for my .flv files, it should be a simple matter to indicate that they should open with adobe flash player, but I can't find the application! I have the pathway "C:\Windows\System32\Macromed\Flash" which contains the following f
-
just did the ios 7 update on my iphone 4s and when it got to the apple id security screen it won't let me past it and now i can't get out of it, i tried not entering the security questions by clicking "not now" and also tried entering the info but it
-
Intel Wireless 802.11b/g vs. Apple Wireless Airport
Hi, Does anyone know which is better? Difference in range and speeds? etc...
-
Just spent the past few days with Novell support trying to figure out if I was missing anything with the driver that was released in September To Linux... I'm pretty much a noob, but willing to learn I knew the card was good since it was fine in Vist