What Is Prototype Used For Anyway?
I have been learning actionscript by myself for a few months, and I know about Arrays, Objects, Functions, etc. and how to use them. But the one thing I never used was the function prototype method, or whatever its proper name is.
What exactly is it used for? I cant think of what it could be, all I know is that a lot of these great coders use it, so I figured I might as well know what it is!
So can anyone spare a minute and tell me what exactly its all about!
Cheers.
FlashKit > Flash Help > Flash ActionScript
Posted on: 03-19-2002, 05:04 PM
View Complete Forum Thread with Replies
Sponsored Links:
How Do You Pass A Prototype To A Prototype?
PREFACE: This post is not as long as it looks, I just included my code as an example.
It seems that I am constantly resizing images (in MovieClips) and centering images (also in MovieClips), so I wrote a couple of simple functions to automate the process.
Then I realized that sometimes I don't want to actually center or resize the MovieClip, I just want the properties of the the resized, repositioned MovieClip. So I wrote a couple of new prototypes that basically did the same thing: they created a temporary invisible duplicate, applied the transforms, extracted and returned the properties!
I am sure there's a way that I can use one prototype function for all the transforms, but I don't know how to pass the protoype function in the definition of another prototype.
I would like to say:
ActionScript Code:
var coords:Array = this.predictValues(this.centerIn(this._parent));
this is my center prototype:
ActionScript Code:
MovieClip.prototype.centerIn=function (obj:Object) {
if (obj==""||obj==undefined) {
var srcWidth:Number= Stage.width;
var srcHeight:Number=Stage.height;
var srcScope:MovieClip=_root;
} else if(obj.length==2) {
var srcWidth:Number=obj[0];
var srcHeight:Number=obj[1];
var srcScope:MovieClip=this;
} else if (typeof(obj)=="movieclip") {
var srcWidth:Number=obj._width;
var srcHeight:Number=obj._height;
var srcScope=obj;
} else {
var srcWidth:Number=this._width;
var srcHeight:Number=this._height;
var srcScope=this;
}
var startX:Number=srcScope._x;
var startY:Number=srcScope._y;
var centerW:Number = Math.round((srcWidth-this._width)/2);
var centerH:Number = Math.round((srcHeight-this._height)/2);
this._x=startX+centerW;
this._y=startY+centerH;
}
this is my fitIn prototype
ActionScript Code:
MovieClip.prototype.fitIn = function(obj:Object) {
trace (typeof(obj));
if (obj == "" || obj == undefined) {
var maxWidth = Stage.width;
var maxHeight = Stage.height;
} else if (obj.length == 2) {
var maxWidth = obj[0];
var maxHeight = obj[1];
} else {
if (typeof (obj) == "movieclip") {
var someClip = obj;
var maxWidth = someClip._width;
var maxHeight = someClip._height;
} else {
var maxWidth = this._width;
var maxHeight = this._height;
}
}
var ratioW2H:Number = this._width/this._height;
var ratioH2W:Number = this._height/this._width;
var adjW_ws:Number = maxWidth;
var adjH_ws:Number = ratioH2W*adjW_ws;
var area_ws:Number = (adjH_ws<maxHeight) ? adjH_ws*adjW_ws : 0;
var adjH_hs:Number = maxHeight;
var adjW_hs:Number = ratioW2H*adjH_hs;
var area_hs:Number = (adjW_hs<maxWidth) ? adjW_hs*adjH_hs : 0;
if (area_ws>area_hs) {
this._width = maxWidth;
this._height = adjH_ws;
} else {
this._height = maxHeight;
this._width = adjW_hs;
}
};
These are the functions that just get the info without transforming the clip:
ActionScript Code:
MovieClip.prototype.findCenterIn=function(obj:Object):Array {
this.duplicateMovieClip(this._name+"temp",this.getNextHighestDepth(),{_visible:false});
var temp=this._parent[this._name+"temp"];
temp.centerIn(obj);
var reslt:Array = new Array(temp._x, temp._y);
temp.swapDepths(999);
temp.removeMovieClip();
return (reslt);
}
MovieClip.prototype.findFitIn=function (obj:Object):Array {
var temp=this._parent[this._name+"temp"];
temp.fitIn(obj);
var reslt:Array = new Array(temp._width, temp._height);
temp.swapDepths(999);
temp.removeMovieClip();
return (reslt);
}
As you can see these last two are basically the same function.
So what I am asking is how to make this work:
ActionScript Code:
MovieClip.prototype.findResults(someFunc:Function, obj:Object):Array {
var temp=this._parent[this._name+"temp"];
// here's the problem:
temp.call(someFunc(obj));
//????
var reslt:Array = new Array(temp._width, temp._height, temp._x, emp._y);
temp.swapDepths(999);
temp.removeMovieClip();
return (reslt);
}
Sorry for the ridiculously long post. Thanks for any help or advice you can give.
Jase
View Replies !
View Related
Does An MC Have A Prototype?
You can assign variables to an MC instance like so:
onClipEvent(load){
this.sillyVariable = 15;
}
Say I want to add a method/function to all instances of an MC. Wouldn't I need to add it to the MC's prototype object? (It doesn't seem to exist)
The following works, but is a bit inefficient I would think for many MC instances:
onClipEvent(load){
this.sillyVariable = 15;
this.MyFunction = function(value){ trace(value); }
}
Any thoughts?
What I am trying to do is create reusable components without going the smart clip route. This way I could drop a couple of MC instances in a new project and make function calls and set up properties, etc...
View Replies !
View Related
Prototype
What is one? Ive seen it used like:
thing.prototype.something = blah blah blah...
But I have no idea what it does, and I cant find anything in the help files about it.
View Replies !
View Related
Prototype MC
How to pass the name of a mc to a prototype function?
My program consists of:
Two Mc and one prototype for the program.
First MC is named as Green (which has got one button inside for startDrag)
second Mc Is named as GreenR
with one prototype function
How to pass the name of the second MC from first MC to prototype
This program is not working (coz of the right is a string).
-----------------------------
My Prototype function in scene 1 as follows
MovieClip.prototype.myMove = function(){
right = this._name+"R"
x_pos = this._x;
y_pos = this._y;
if (eval(this._droptarget) == right){
this._visible = false;
} else {
this._x = x_pos;
this._y = y_pos;
}
}
---------
First MC function
onClipEvent(load){
this.myMove();
}
First Mc has a button inside it
on(press){
startDrag(this);
}
on(release){
stopDrag();
}
View Replies !
View Related
Help With Prototype
I'm trying to create a prototype but the method i add to the prototype doesn't seem to be wanting to stick. Am I missing something because the function isn't being created in spawn.
duplicate.prototype = new MovieClip();
duplicate.prototype.method = function () {
trace (this._visible);
}
Object.registerClass("duplicator", duplicate);
function createmovie(name, depth) {
attachMovie("duplicator", name, depth);
}
createmovie("spawn", 5);
spawn.method();
stop();
View Replies !
View Related
About Prototype~
Hi all~
I made an experiment for inheritance but something confused me alot. that is the ways of declaring methods, plz check the code first:
code:
function Human()
{
this.head = 1;
this.walk = function(){return "human can walk~";}; // internal declaration for method~
}
Human.prototype.temp = function(){return "temp method here~";}; // external method~
when we trace method temp everthing goes right:
code:
trace(Human.prototype.temp(); // prints that string~
but a second trace for walk method we met the problem:
code:
trace(Human.prototype.walk(); // Oops we get a undefined !
and same things happens for tracing Human.walk, then where could we find walk method without inheritance(the emphisis is not using inheritance) ???
thanx in advance~
View Replies !
View Related
AS 1 & 2 - What Would You Use Instead Of PROTOTYPE?
Hello
i am switching all my code to AS2... I love it...
but there is still something I am missing....
I built so many functionalities inside prototype functions of built in objects....
MovieClip.prototype was the most used for motion effects....
How would you translate such a simple thing in AS2?
thank you and enlightment
Pippo
View Replies !
View Related
Prototype Help
i'm trying to create a generic open/close switch for an MC.
here is my code
Code:
tog = function (item) {
if (item.isClosed) {
opn(item);
} else {
cls(item);
}
};
cls = function (item, x, y, speed,scale, fade, callback) {
item.slideTo(x, y, speed,scale, fade, callback);
};
opn = function (item,x, y, speed,scale, fade, callback) {
item.slideTo(x, y, speed,scale, fade, callback);
};
i'm trying to create it so I can say:
Code:
mybutton.onRelease=function(){
mymenu1.cls
mymenu2.opn
}
I'd like to also construct a prototype so that I can dynamically set those attributes in the constructor for a specified object. The attributes will be specific to the object i'm attaching the proto to.
Code:
mymenu.prototype.togglescript=function(){
//set all specific attribuites
}
I'm not sure if any of this makes any sense, reply and I"ll explain more.
View Replies !
View Related
Can Someone Help Me With My Prototype?
Hi,
I created a prototyped to format my flash form elements, namely the TextFields. It almost works, except I can't get the
onSetFocus and onKillFocus functions working...It has something to with the fact my prototype is a MovieClip and these are TextField functions, but I cant figure out for the life of me how to make it work.
Thanks in advance
code:
// ActionScript Document
_global.FormatForm = function(form){
this.form = form;
this.init();
};
FormatForm.prototype = new MovieClip();
FormatForm.prototype.init = function(){
// --------------------
// TextField Styles
// --------------------
this.normal_border = 0xCCCCCC;
this.select_border = 0x000000;
this.normal_background = 0xEEEEEE;
this.select_background = 0x0066FF;
this.normal_color = 0x999999;
this.select_color = 0x666666;
this.format();
};
FormatForm.prototype.format = function(){
for(var a in this.form)
{
this.form[a].border = true
this.form[a].borderColor = this.normal_border
this.form[a].background = true
this.form[a].backgroundColor =this.normal_background
this.form[a].textColor = this.normal_color
this.form[a].onSetFocus = this.selected();
this.form[a].onKillFocus = this.deselected();
}
};
FormatForm.prototype.selected = function()
{
this.borderColor = this.select_border
this.backgroundColor = this.select_background
this.textColor = this.select_color
}
FormatForm.prototype.deselected = function()
{
this.borderColor = this.normal_border
this.backgroundColor = this.normal_background
this.textColor = this.normal_color
}
Oh and the reason why ive declared it as _global function is because I want to add this to a global_functions.as file i created which i'll #include in the main movie so that all child movies can access repeatedly used functions (such as this)
View Replies !
View Related
When To Use Prototype ?
When/if should I prototype AS 2.0 classes? I want to extend the functionality of AS 2.0 classes Object, XML, and Array. I have not found much about the origins of "prototype".
Was this something MX 2004 that was depreciatedin 2005?
Is it still a good idea to use it?
Will it be going away in the future?
Code:
Object.prototype.convertToXml - function{
}
So obviouly the other option is to extend the class
Code:
class Object2 extends Object{
function Object2{
}
function convertToXml():XML{
}
}
the big disadvantage with extending the class is that I can't get the compiler to treat "Object2" as an Object. (i guess that I could make it a dynamic class, but I have avoided using dynamic classes up to now b/c they seem sloppy to me.)
ex:
Code:
var myObj2:Object2 = new Object2();
var myStr:String = "hello world";
myObj2.myStr = myStr; // Compiler Error Here! "here is no property with the name 'myStr '."
ideas, thoughts, sugestions?
ty
--mm
View Replies !
View Related
Prototype
Why doesn't this work with attachMovie?
Code:
MovieClip.prototype.onLoad = function() {
trace(this);
};
//
_root.attachMovie("testMC", "testMC", 1);
View Replies !
View Related
What's A Prototype?
hi guys...i have seen it too many times to finally let it pass. I googled this, but i still can not find a really clear explanation in basic terms of what a protoype is, and how to use it. Part of the problem is that the definitions refer to a "superclass" which i am not familiar with. But also, the help document in flash refers to it in terms over my head...can someone put it in layman's terms?
View Replies !
View Related
What Exactly Is A Prototype?
Ive seen it around and searched for an explanation on its purpose and found nothing. Checked out the new aweful flash help file and couldnt make sense of things.
Im not some guru programmer so I dont understand classes either and it seems like its a "super" class. Well, what's the difference between a class and function?
Maybe if I understand the difference between a class and function a prototype may make sense 0o
View Replies !
View Related
Prototype And This.?
I'm trying to make this script, and I'm also practicing some OOP-techniques I've read.
But I can't seem to get it to work - why isn't this working:
Code:
onEnterFrame=function(){
Aimpoint();
}
function Aimpoint() {
this.addIt();
this.moveIt();
}
Aimpoint.prototype.addIt = function() {
if (!_root.aimpoint) {
_root.attachMovie("aim","aimpoint",10,_root)
}
}
The code in bold simply never gets called...
Can't I call a functions methods from within itself?
View Replies !
View Related
Prototype
Hi,
I tried overwrite the loadMovie function by the following commands
MovieClip.prototype.loadMovie = function() {
mc_loc = this;
trace(arguments+":::::::::ver written:::::::::::::::"+mc_loc);
};
but it over write only the following syntax [MovieClip.loadMovie(url)]
fl = "YourImage.jpg";
container_1.loadMovie(fl);
not overwrite the following syntax [loadMovie(url,target)]
loadMovie(fl,container_1)
Plz help me to overwrite the second sytax function also
View Replies !
View Related
XML.prototype
hello,
I'd like to add two new methods to the 'XML' class: "nextSibling()" and "previousSibling()". I'd like these 2 methods available anytime I need to manipulate and :XML type object, further in my code.
For now, I've done the following, but it doesn't seem to work. And I'm not sure where to place this code, so I've putted it in my main class:
Code:
package com.tlv.players{
import ...;
// With "this"
XML.prototype.nextSibling = function() {
return this.parent().children()[this.childIndex() + 1];
}
// With full package
XML.prototype.previousSibling = function() {
return XML.prototype.parent().children()[XML.prototype.childIndex() - 1];
}
public class MediaPlayer extends MovieClip {
...
public function MediaPlayer() {
...
}
}
}
Thanks for your help !
Regards,
Alex
View Replies !
View Related
Prototype And AS3
Hello,
I'm trying to use this two prototypes in AS3 but doesn't work and neither shows any error. Anybody knows why? Can someone help me converting this code to AS3???
Thanks
-------------------------
//fade in
MovieClip.prototype.fadeIn = function(fade) {
this.onEnterFrame = function() {
(this._alpha>=(100)) ? (this._alpha=100, delete (this.onEnterFrame)) : this._alpha += fade;
};
};
//_root.logo.fadeIn(10);
//
MovieClip.prototype.elastico_X = function(tx, ty) {
var f = 0.2;
var r = 0.3;
//f = fricion r= ratio
var xtam = 0;
var ytam = 0;
this.onEnterFrame = function() {
this._x += (xtam=xtam*f+(tx-this._x)*r);
this._y += (ytam=ytam*f+(ty-this._y)*r);
};
};
View Replies !
View Related
Prototype
i'm a bit confused about the usage of "Prototype"...
i found some tutorial with an Array.Prototype function, which i understood,
but i was actually curious if i can use this Prototype function (to be declared in some empty frame) and call it in any MC i want, at any moment, for any event.
this is, since i'm creating a game: i have lots of functions, and especially one is called in many different MCs. Actually i declared the same function in every MC (onClipEvent (load)) and then call it later on (onClipEvent(EnterFrame)).
is there any way i can declare it only one time, and then call it in different MCs?
View Replies !
View Related
Prototype Help
I was under the impression that I could use a prototype to set a default value for all reoccuring objects in a flash. For instance, I'm trying to achieve an effect where all text fields created will be unselectable.
TextField.prototype.selectable = false;
does not seem to be working... have I got it all wrong, and if so, how do I achieve this effect?
Thanks,
Rege
View Replies !
View Related
Prototype
MovieClip.prototype.onRelease = function(){
trace ("working");
delete this; // what this delete will remove
};
box2.onRelease();
what the statement "delete this" will remove? actually what that will perform.....
anyone know this....????
Edited: 12/07/2006 at 01:20:50 AM by steeban
View Replies !
View Related
Prototype
Can anyone tell me why I can't prototype Sprite?
Sprite.prototype.sayHello = function(){
trace("hello");
}
spr:Sprite = new Sprite();
spr.sayHello();
This gives a 1061 error. Although replacing the last 2 lines with
mc:MovieClip = new MovieClip();
mc.sayHello();
works fine. The first version works fine if I turn off strict mode, but I don't want to do that obviously.
This also works fine
Array.prototype.sayHello(){
trace("hello");
}
arr:Array = [];
arr.sayHello();
It seems like prototyping Graphics causes the same error. It works, so can anyone tell me why it produces a compiler error?
View Replies !
View Related
Prototype And AS3
Hello,
I'm trying to use this two prototypes in AS3 but doesn't work and neither shows any error. Anybody knows why? Can someone help me converting this code to AS3???
Thanks
Attach Code
//fade in
MovieClip.prototype.fadeIn = function(fade) {
this.onEnterFrame = function() {
(this._alpha>=(100)) ? (this._alpha=100, delete (this.onEnterFrame)) : this._alpha += fade;
};
};
//_root.logo.fadeIn(10);
//
MovieClip.prototype.elastico_X = function(tx, ty) {
var f = 0.2;
var r = 0.3;
//f = fricion r= ratio
var xtam = 0;
var ytam = 0;
this.onEnterFrame = function() {
this._x += (xtam=xtam*f+(tx-this._x)*r);
this._y += (ytam=ytam*f+(ty-this._y)*r);
};
};
View Replies !
View Related
AS1 I Use Prototype, AS2 I Use ?
Allright, i need a bit of help.
i want to do a simple function and incorpore it into every mc in my flash movie.
In mx, i use prototype, but in mx2004, you cannot use it.
how would you assign a function to selected mc's on the stage.
here what i use in mx:
---
MovieClip.prototype.xTraceName= function(){
trace(this);
};
// on first frame of mc
this.onRollOver=function(){
this.xTraceName();
};
---
how can i do the same in as2 using class or subclass ?
View Replies !
View Related
Prototype?
i often see prototype in actionscripts but i have no idea what it means.
usually i will see it as MovieClip.prototype.somethingelse
sometimes i will see others.prototype
what does this prototype stands and wat is its function?
thanks
View Replies !
View Related
Prototype
As I was wokring my way through the AS tutorials, I got to the arrays and noticed that it used prototype. Sorry, but I have little clue as to what it does. If somebody could answer this, that would bre great. Thanks in advance
View Replies !
View Related
Prototype Help
Hey,
Why wont work this prototype ?
I dont understand it.
You can download the fla here
What do it need to do: When you roll-over a piece of the skyline it need to resize to that defined number.
I putted the code in a for()-loop.
View Replies !
View Related
Lil Prototype Q
quick question about prototypes... sry if this is a scrub question and all that... i searched yes i did and didnt find the answer and i figured it should be a quick answer so i'd post.
according to my latest experiment.. you cant call a prototype twice at the same time from 2 different buttons.
is that right?
i can give an example if needed to clarity.
thanks for any help
View Replies !
View Related
Prototype ?
Hi, i was checking the code for the resizable gallery that's on "best of k", and i found this code:
Code:
MovieClip.prototype.loadPic = function(pic){
_root.containerMC._alpha = 0;
this.loadMovie(pic);
_root.onEnterFrame = function(){
var t = containerMC.getBytesTotal(), l = containerMC.getBytesLoaded();
if (t != 0 && Math.round(l/t) == 1){
var w = containerMC._width + spacing, h = containerMC._height + spacing;
border.resizeMe(w, h);
delete _root.onEnterFrame;
}
}
};
i'm "returning" to flash, after a year, almost two, so i dont remember that "prototype" function...
so, can someone plz explain it to me ???? :S what is it for? is it used instead of something else?....
View Replies !
View Related
Help With A Prototype
i need help with a prototype that calls another prototype... hope u get it
ActionScript Code:
MovieClip.prototype.tracing = function() { trace(this._name+"\n\thello, how are u doing?");};MovieClip.prototype.calling = function(proto) { this.proto();};
is that ok?
if it is.. how should i call the function "calling"?
1.- this.calling(tracing)
2.- this.calling(MovieClip.prototype.tracing)
none of that works
(dont worry if u think this is nonsense, im working with bigger prototypes, this was simplified to show my problem and nothing else)
View Replies !
View Related
Help On A Prototype
Hi everyone,
i can't find an issue on this problem:
I have a prototype
PHP Code:
TextField.prototype.changeHtmlText = function(texte:String, oldColor, effectSpeed, myTextStyle) { oldColor = (oldColor == undefined) ? "#4A6C99" : oldColor; if (myTextStyle == undefined) { var myTextStyle = new TextField.StyleSheet(); myTextStyle.setStyle("a", {color:"#ff7800", textDecoration:"none"}); //links myTextStyle.setStyle("a:hover", {color:"#99cc00", textDecoration:"none"}); //hover links } cx = this._parent.createEmptyMovieClip("texteTempControl"+this._parent.getNextHighestDepth(), this._parent.getNextHighestDepth()); this.styleSheet = myTextStyle; if (cx.tempcaixadetexte == undefined) { cx.createTextField("tempcaixadetexte", cx.getNextHighestDepth(), 0, 0, 0, 0); } cx.setTextFormat(textformat); cx.tempcaixadetexte.htmlText = this.htmlText="<font color='"+oldColor+"'>"+this.text+"</font>"; cx.textefullsize = texte.length; cx.thisfullsize = cx.tempcaixadetexte.text.length; cx.texte = texte; cx.effectSpeed = (effectSpeed == undefined) ? 5 : effectSpeed; cx.caixa = this; cx.onEnterFrame = function() { this.effectSpeed = int(this.texte.length/this.effectSpeed)+1; this.velActual = Math.min(this.effectSpeed, this.texte.length); this.pedacotexte = this.texte.substr(-this.velActual); if (this.pedacotexte.indexOf(">")>-1) { this.velActual = this.texte.length-this.texte.lastIndexOf("<"); this.pedacotexte = this.texte.substr(-this.velActual); } this.texte = this.texte.slice(0, -this.velActual); this.tempcaixadetexte.text = this.pedacotexte+this.tempcaixadetexte.text; this.tempcaixadetexte.text = this.tempcaixadetexte.text.slice(0, this.textefullsize-this.texte.length+int(this.thisfullsize*(this.texte.length/this.textefullsize))); this.caixa.htmlText = this.tempcaixadetexte.text+"</font>"; if (!this.texte.length) { this.removeMovieClip(); } };};this.createTextField("test", this.getNextHighestDepth(), 20, 20, 200, 200);test.multiline = true;test.html = true;test.wordWrap = true;//actual texttest.htmlText = "OLÁ, bem vindo,<br/><br/>Eu sou Paulo Afonso.<br/> o meu <a href='http://www.semmais.com'>site </a> e o meu <a href='http://forum.semmais.com'>fórum </a><br/><br/> Obrigado";//new textnewText = "HELLO, welcome,welcome,welcome,welcome,<br/><br/>My name is Paulo Afonso, visit <a href='http://www.semmais.com'>website </a>, my <a href='http://forum.semmais.com'>fórum </a><br/><br/> thanks";test.changeHtmlText(newText);
Try it to see what it does.
My problem is that i can't use it if i want to embed a font and seriously i don't understand why. I try to create a new textFormat, it doesn't work. the only thing that works is when i add this :
PHP Code:
cx.tempcaixadetexte.htmlText = this.htmlText="<font face='myfont' color='"+oldColor+"'>"+this.text+"</font>";
When it works weird.
If someone can lok at that and tell me what's wrong i would appreciate.
Thank you again for your help.
Chris
View Replies !
View Related
AS1 I Use Prototype, AS2 I Use ?
Allright, i need a bit of help.
i want to do a simple function and incorpore it into every mc in my flash movie.
In mx, i use prototype, but in mx2004, you cannot use it.
how would you assign a function to selected mc's on the stage.
here what i use in mx:
---
MovieClip.prototype.xTraceName= function(){
trace(this);
};
// on first frame of mc
this.onRollOver=function(){
this.xTraceName();
};
---
how can i do the same in as2 using class or subclass ?
View Replies !
View Related
Prototype?
i often see prototype in actionscripts but i have no idea what it means.
usually i will see it as MovieClip.prototype.somethingelse
sometimes i will see others.prototype
what does this prototype stands and wat is its function?
thanks
View Replies !
View Related
Prototype
As I was wokring my way through the AS tutorials, I got to the arrays and noticed that it used prototype. Sorry, but I have little clue as to what it does. If somebody could answer this, that would bre great. Thanks in advance
View Replies !
View Related
Prototype Help
Hey,
Why wont work this prototype ?
I dont understand it.
You can download the fla here
What do it need to do: When you roll-over a piece of the skyline it need to resize to that defined number.
I putted the code in a for()-loop.
View Replies !
View Related
Prototype?
Just curious here...
I have, let's say, 50 movie clips.
I want the movie clips to do something on rollover.. the will all do slightly similar things
on(rollover){
do x; //where x will be a variable
}
Is there actually a way that will save me from adding the code to each button?
Meaning, I don't want to do,
function doit(){}
button1.onRollover=doit;
button2.onRollover=doit;
button3.onRollover=doit;
Im thinking protoype? Hmm... Pom, c'mon dude. Although I understand the basic concept, I simply have not applied it to date.
View Replies !
View Related
Lil Prototype Q
quick question about prototypes... sry if this is a scrub question and all that... i searched yes i did and didnt find the answer and i figured it should be a quick answer so i'd post.
according to my latest experiment.. you cant call a prototype twice at the same time from 2 different buttons.
is that right?
i can give an example if needed to clarity.
thanks for any help
View Replies !
View Related
Prototype Help
I seem to be having trouble with this, I will explain:
I have an MC that contains 14 MC children , each of those has a tween, and I am trying to setup a "rewind" so that when someone does the mouseover, they can hit the down key to rewind the tween. This is what I have.....
parentMC (instance name "words")has within it:
onClipEvent(enterFrame){
this.Go(!(Key.isDown(Key.DOWN)));
}
Frame 1 of the main timeline has this:
words.prototype.Go = function (dir) {
gotoAndStop ((!dir) ? (_currentframe == 1) ? _totalframes : prevFrame () : play ());
}
I am quite new to this, so I will need help
View Replies !
View Related
As 1 To AS 2 (prototype)
I have a frame work which uses OPPs concepting using prototype , but i am not very aware of opps concept as such but i have given responsible of changing whole frame work into as2 which has prototyping can any body help help
how to change prototyping into as2? or any link
View Replies !
View Related
Help With Prototype
i'm trying to make a prototype that rotates a movieclip according to the speed while it's being dragged. my prototype is like this:
ActionScript Code:
MovieClip.prototype.rotateMC = function() {
//on button press function
this.onPress = function() {
//varibles
this.counterPos = 0;
this.friction = 0.8;
//generic actions
this.swapDepths(this._parent.getNextHighestDepth());
this.startDrag(false);
//
//drag speed
this.onEnterFrame = function() {
this.counterPos++;
this["mouseX"+this.counterPos] = _root._xmouse;
this["mouseY"+this.counterPos] = _root._ymouse;
this.oldX = this["mouseX"+(this.counterPos-1)];
this.newX = this["mouseX"+this.counterPos];
this.oldY = this["mouseY"+(this.counterPos-1)];
this.newY = this["mouseY"+this.counterPos];
this.dragSpeed = Math.sqrt(Math.pow((this.newX-this.oldX), 2)+Math.pow((this.newY-this.oldY), 2));
this._rotation += this.dragSpeed;
};
};
//
//on button release function
this.onRelease = this.onReleaseOutside=function () {
// generic actions
this.stopDrag();
//rotation inertia
this.onEnterFrame = function() {
this.dragSpeed = this.dragSpeed*this.friction;
this._rotation += this.dragSpeed;
if (Math.abs(this.dragSpeed)<1) {
this.dragSpeed = 0;
delete this.onEnterFrame;
}
};
};
};
i want the movie clip to have an inertia function so that it keeps rotating, until the speed reaches zero, after it is stop being dragged.
i can't seem to get the right effect. please help
View Replies !
View Related
[AS] Prototype
Im a bit confused as to how prototypes are supposed to work, and how to pass variables through them. Below is a piece of code that I cant seem to get working. In theory it "should" call all the mc's _height from #3 and up.
If anyone could give me a quick idea of what Im doing wrong I would greatly appreciate it.
ActionScript Code:
this.onLoad = function() {
count = 5; // I have 6 mcs named 0-5
check(3); // I want to trace (3-5)
}
function check(num) {
for (i=num; i<=count; i++) {
this[i].getHeight(i); //calls prototype for each mc?
}
}
MovieClip.prototype.getHeight = function() {
foo = this[i]._height;
trace(foo) // returns "undefined"
}
View Replies !
View Related
Prototype In F-MX
i want to know how it work's the "prototypes" in Flash MX... i've got a code wrote in Flash 5 and i need apply it in Flash MX...
please i'll gonna need any suggestions---
View Replies !
View Related
What's This 'prototype' Business?
Hi,
I keep seeing this 'prototype' term around a lot....
as in
_root.Array.prototype[i]
and I'd really like to know what that is used for! Might come in handy methinks, is it a reference to a temporary variable or array created within a script process?
Flash Actionscript Dictionary is very quiet about this one, like a lot of useful items...of course if it's just a variable like any other I feel pretty stupid right about now....but I thought it was worth asking anyway.
[Edited by InBhava on 09-19-2001 at 07:20 AM]
View Replies !
View Related
Mouse Prototype
i was wondering if you can add methods to the mouse object? i can't figure out how to?
this is what i'm doing. is that correct?
Mouse.prototype.something = function ()
{
trace("something");
}
any help would be helpful.
thanks
jefmyers
View Replies !
View Related
Prototype Function
Ok this prototype is whipping my ass I have a mc called window which I want to grow according to which button is pressed . I only have one button in there for now but I want it to grow to size of what the button passes it .
Code:
movieclip.prototype.grow=function (txscale,tyscale,tx,ty) {
this.txscale=txscale;
this.tyscale=tyscale;
this.tx=tx;
this.ty=ty;
}
movieclip.prototype.growNow=function () {
if (home) {
_xscale+=(txscale-_xscale)/3;
_yscale+=(tyscale-_yscale)/3;
_x+=(tx-_x)/3;
_y+=(ty-_y)/3;
}
}
//==================================
Button code
on (release) {
_root.home=true;
_root.window.growNow(50,50,239,152);
I have the mc, window scaled to 2 % o the xscale and the yscale and what I cant do is get it when the button is pressed to scale to 50, 50, % what is happening is it flys to the top left of the screen and disappears . the reason i'm doing it this way is because I will have a lot of buttons and I just want to be able to pass the pisitions and scale to the function from the button .
[Edited by ericflash on 03-20-2002 at 07:16 PM]
View Replies !
View Related
|