Prototype Within Class
I have a prototype for searching arrays and array elements for a specified string. If I use the #include directive within the .fla file I can access this prototype no problem. But, I need to use the prototype within a custom class file. How can I accomplish this? I attempted to use the #include directive in the class file, but the compiler throws an error. Any help is appreciated.
ActionScript.org Forums > ActionScript Forums Group > ActionScript 2.0
Posted on: 01-25-2007, 04:09 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Class.prototype?
In AS2 you could say something along the lines of:
MovieClip.prototype.onPress = function() { // Statements }
But I can't figure out how to achieve the same effect with AS3. I'd need to create an event listener and have a function to call, but I can't anything to work. So, what do I do?
Thanks a lot!
EDIT: Also, how do I add an event listener inside a class? Can't get that to work either!
Prototype Within Class.
I have a prototype for searching arrays and array elements for a specified string. If I use the #include directive within the .fla file I can access this prototype no problem. But, I need to use the prototype within a custom class file. How can I accomplish this? I attempted to use the #include directive in the class file, but the compiler throws an error. Any help is appreciated.
Use Prototype In Class - How?
I've got an XML prototype I'd like to use within a custom class I've built, but alas, you can't define prototypes in a class.
How do I get this to work?
Example:
The prototype:
ActionScript Code:
XMLNode.prototype.getNodeByName = function(name, recurse) {
var node = this;
if (!recurse) {
theNode = xxx;
}
for (var i = 0; i<node.childNodes.length; i++) {
if (node.childNodes[i].nodeName.toLowerCase() == name.toLowerCase()) {
theNode = node.childNodes[i];
break;
} else {
if (node.childNodes[i].hasChildNodes) {
node.childNodes[i].getNodeByName(name, true);
} else {
theNode = "";
}
}
}
return theNode;
};
The class:
ActionScript Code:
class myCustomClass {
// properties:
private var _formXML:XML;
//constructor:
public function myCustomClass () {
// Create a new XML object.
var myXML:XML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(success) {
_formXML = myXML;
_parseForm();
};
myXML.load("sampleForm.xml");
}
// methods:
private function _parseForm(): {
var questionNode:XMLNode = _formXML.getNodeByName("questionFormat");
var optionNode:XMLNode = _formXML.getNodeByName("optionFormat");
var generalNode:XMLNode = _formXML.getNodeByName("generalFormat");
trace("questionNode: " + questionNode);
}
}
[F8] Convert Prototype To Class?
Greetings all,
I have been using this code to replace string items:
String.prototype.replace = function(pattern, replacement)
{
return this.split(pattern).join(replacement);
}
COutput.text = CString.text.replace(CWhat.text, CWith.text);
I am hoping someone can help me convert this to a Class file if possible. I use this quite a bit in my education apps and hope to be able to keep the functionality.
Any assistance will be greatly appreciated.
Call Class With Prototype Way
Hello there
I'm trying to learn to write classes. I'm avanced user in Flash but i don't know how to write classes, so i'm working on it.
A way to write a class into Flash is the Prototype and i love this way of write functions but because i want to learn classes, i try writing a class using an example that i get and this is what i did:
PHP Code:
class MoveObj{ private var objLastX : Number; private var objLastY : Number; // public function moveThis (theObj : MovieClip, newPosX : Number, newPosY : Number, vel : Number) : Void { theObj.onEnterFrame = function () : Void { objLastX = this._x; objLastY = this._y; // this._x += Math.round ((newPosX - this._x) / vel); this._y += Math.round ((newPosY - this._y) / vel); // if (objLastX == this._x && objLastY == this._y) { delete this.onEnterFrame; trace ("Done"); } } }}
I save this file with the name "MoveObj.as", then later in Flash i call the class on this way:
var move:MoveObj = new MoveObj();
move.moveThis(sqr_mc, random(Stage.width), random(Stage.height), 10);
All working right... AND I LOVE IT... WAS MY FIRST CLASS !!!!!!!
But now i want to call the class in Flash on this way:
sqr_mc.moveThis(random(Stage.width), random(Stage.height), 10);
This is the way i call a prototype write it for a MovieClip into Flash. How i need to change the class to call it on this way ??????
And the same time, please suggest me some sites were i may learn more about classes, please.
Thanks a lot for any help.
Convert Prototype To Class?
Greetings all,
I have been using this code to replace string items:
String.prototype.replace = function(pattern, replacement)
{
return this.split(pattern).join(replacement);
}
COutput.text = CString.text.replace(CWhat.text, CWith.text);
I am hoping someone can help me convert this to a Class file if possible. I use this quite a bit in my education apps and hope to be able to keep the functionality.
Any assistance will be greatly appreciated.
Prototype Tween Class
Does anyone know if there is a prototype version of robert penners tween class that i could use in a flash 5 movie. Would make my life a hell of a lot easier
james
MovieClip.prototype And As2 Class
Hi there..
i have two questions..
the first what exactly does the function "MovieClip.prototype" means is it a sort of class?
I ask this question because i have a lot of resizing scripts in my flash movie. i think too much because they are not always working fine anymore.
Is it possible to write a class for resizing? because a lot of the movieclips must be in the middle of the screen. Even when resizing it has to be in the middle. Some of the clips are not moving anymore when resizing. So i thought if i add a class .as file it maybe works better. i never work with classes in flash and that's only because i do not know the real meaning of it. If someone can explane me the meaning and quality of classes. And ofcourse how to add them to the several movieclips.
Thanks
Converting As2 Class That Used Prototype Into As3
Hello,
i was using this typewriter function in as2 that launched the following way:
Code:
textfield1.typewriter(text1, "", 1);
text1 is the new text to animate, "" is the blank text, and 1 is the speed (there are 3 more values but they are not needed at this time)
now, in the as file called typewriter.as that used to be included using
Code:
#include "typewriter.as"
was the following code using prototype. This being a long piece of code, i do not expect anyone to convert all of it, i just need a push with two things. How to call that same function in as3, and how to write the beginning of this new class (without prototype since it seems it is not the proper way of doing it anymore). Below this sample, is the attempt i have made at writing the package. Thanks:
Code:
//************************************************************//
// A NICE TYPEWRITER TEXT EFFECT
//************************************************************//
trace("as load");
MovieClip.prototype.typewriter = function(newtext:String, oldtext:String, lspeed:Number, blinkdelay:Number, f, v):Void {
//trace(newtext+" newtext in as file");
//trace(oldtext+" oldtext in as file");
//trace(lspeed+" lspeed in as file");
this.charToUse = " ";
//
if (oldtext == null) {
oldtext = "";
}
this.temptext = oldtext;
this.counter = 0;
this.i = oldtext.length;
if (lspeed == null) {
lspeed = 1;
}
if (blinkdelay == null) {
blinkdelay = 31;
}
this.onEnterFrame = function():Void {
for (mylspeed=0; mylspeed<lspeed; mylspeed++) {
this.temptext = this.temptext+newtext.charAt(this.i);
if (newtext.charAt(this.i) == "<") {
htmlend = newtext.indexOf(">", this.i);
htmladd = htmlend-this.i;
this.i = this.i+htmladd;
this.temptext = newtext.substr(0, this.i);
continue;
}
this.i++;
}
this.txt.htmlText = this.temptext+this.charToUse;
if (this.i>=newtext.length) {
this.mybool = 1;
this.onEnterFrame = function():Void {
this.counter++;
this.mybool = !this.mybool;
if (this.mybool == true) {
this.txt.htmlText = this.temptext+this.charToUse;
} else {
this.txt.htmlText = this.temptext;
}
if (this.counter>=blinkdelay) {
this.txt.htmlText = this.temptext;
this.counter = 0;
this.blinkremove();
delete this["onEnterFrame"];
f(v);
}
};
}
};
};
//
//************************************************************//
// REMOVE THE MOVIECLIP USED FOR THE TYPEWRITER EFFECT
//************************************************************//
MovieClip.prototype.blinkremove = function():Void {
this.onEnterFrame = function():Void {
this._alpha = this._alpha-10;
this._visible = !this._visible;
if (this._alpha<=0) {
this.removeMovieClip();
}
};
};
//************************************************************//
//
//************************************************************//
/*
MovieClip.prototype.elasticEffect = function(prop:Object, speed:Number, f, param):Void {
this.isAnimating = true;
this.counter = 0;
for (i in prop) {
prop[i] = Math.round(prop[i]);
}
if (speed == undefined) {
speed = 0;
}
if (speed == 0) {
for (i in prop) {
this[i] = prop[i];
}
this.isAnimating = false;
if (f != undefined) {
if (param != undefined) {
f(param);
} else {
f();
}
}
} else {
speed = Math.abs(speed);
// check the vector for similar values and remove them
// this code will make sure the elastic effect is applied
for (i in prop) {
if (this[i] == prop[i]) {
prop = removeObjectElement(prop, i);
}
}
if (prop != null) {
removeMovieClip(this.elastic_effect_temp_mc);
mc = this.createEmptyMovieClip("elastic_effect_temp_mc", this.getNextHighestDepth());
mc.onEnterFrame = function():Void {
var mcObj:MovieClip = this._parent;
var isEqual:Boolean = false;
for (i in prop) {
if (mcObj[i] != prop[i]) {
mcObj[i] += (prop[i]-mcObj[i])/speed;
if (Math.abs(mcObj[i]-prop[i])<1) {
mcObj.counter++;
}
if (Math.abs(mcObj[i]-prop[i])<0.1 || mcObj.counter>=3) {
mcObj[i] = prop[i];
}
} else {
isEqual = true;
}
}
if (isEqual == true) {
delete this.onEnterFrame;
removeMovieClip(this);
for (j in prop) {
mcObj[j] = prop[j];
}
if (f != undefined) {
if (param != undefined) {
f(param);
} else {
f();
}
}
mcObj.isAnimating = false;
}
};
} else {
if (f != undefined) {
if (param != undefined) {
f(param);
} else {
f();
}
}
mcObj.isAnimating = false;
}
}
};
function removeObjectElement(obj:Object, propertyName:String):Object {
var temp:Object = new Object();
var nrElem:Number = 0;
for (i in obj) {
if (i != propertyName) {
nrElem++;
temp[i] = obj[i];
}
}
return (nrElem == 0 ? null : temp);
}
*/
my attempt at rewriting the package:
Code:
package com.as3classes{
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.events.Event;
//import flash.display.MovieClip;
import flash.display.Sprite;
import flash.text.*;
public class Typewriter extends TextField { // i am not sure what extends does but this felt like the proper one if anything
//public class Typewriter {
public function typewriterEffect(value1:String, value2:String, value3:String) {
//i don't know if writing it this way will allow me to write the function in the fla
//as i used to like textfield1.typewriter(value1, value2, value3)!!!!
}
}
}
Class Construction Versus Prototype?
Okay, i'm reading a book, Flash MX Actionscript:Advanced Training from the source..
for any of you who have the book, my question is due to pages 182-187.
These pages explain how to create custom classes by making a class constructor function (may not be using the right terminology), then a few pages over, the book discusses the prototype object...
It seems to me that the prototype object does essentially the same as a class constructor, except it defines properties for an object that already exists...
can someone give me a concrete example of the benefits of using one over the other?
how about some real world examples or something..
thanks for your time..
-myk
-"moo?"
Custom Objects, Class, Prototype
Hello all,
can anyone help create an Object, function class whatever it is, that would response to this code:
Code:
var Mouse = Something.getMouseValue();
trace(Mouse.x,Mouse.y);
don't worry about the actual values of x and y i just want to know how do i give my user the option to get x and y trough the above code.. so what my code should look like to response to the above code and return the values to the user... thanks guys.
Oh yah it should be compatible with Flash MX... and MX 2004...
Converting Specific Prototype To AS2.0 Class
hey all. i have a prototype that i wrote a while ago that tweens any mc to a new x,y destination. i would like to migrate this prototype to as2.0 so i can put it in an external class file, but im not really sure how to go about doing it. if anyone could explain how this to me, i would be greatly indebted. cheers!
MovieClip.prototype.moveIt = function(newX, newY, ease, inertia) {
e=this.createEmptyMovieClip("engineMoveIt",750);
e.newX=newX; e.newY=newY; e.ease=ease; e.inertia=inertia;
e.dx=e.dy=0;
e.onEnterFrame=function() {
mc=this._parent;
this.dx= this.newX - mc._x + this.dx*inertia;
this.dy = this.newY - mc._y + this.dy*inertia;
if ( (Math.abs(mc._x-this.newX)<1) && (Math.abs(mc._y-this.newY)<1) ) {
mc._x=this.newX;
mc._y=this.newY;
this.removeMovieClip();
delete this.onEnterFrame;
} else {
mc._x += this.dx*this.ease;
mc._y += this.dy*this.ease;
}
}
}
String Prototype Not Working In Class
I found this nifty little Trim prototype on proto51.com.
It works a charm except when I start using it in my classes. At least, it kind of works...
Let me explain more:
I have put the prototype in a #include file and I include it before any other code runs in my FLA.
Now, when I use it in my class, and I try to use str = str.Trim(), Flash says that there is an error in my script.
Line 209: There is no method with the name 'Trim'. str = str.Trim();
However, if I use this.searchStr.text = this.searchStr.text.toString().Trim();, it works fine. This is odd. I thought that as soon as I declared a variable (var str:String = "Something") it also inherits all of the prototypes and stuff. Could it be that I should decalre my String as var str:String = new String()?
Any thoughts on this. If I am doing it wrong, then please correct me in my ways.
Thanks!
Trying To Get Prototype Function To Fire In A Class
I am trying to write an actionscript file to take the place of a series of
movie clips.
the specific line that I am trying to find the right call for is :
this.onEnterFrame = this.fly;
I haved tried this which is recomented by livedocs but the finction does not
fire.
ScrollMsg.fly();
I can't use onEnterFrame because that frame is not available.
function ScrollMsg() {
trace("NS--Loaded Scroller");
this._x = 30;
this._y = 0;
trace("this._y"+this._y)
this.createTextField("Msg", 0, 0, 0, this.msgwidth, 10);
trace("ScrollMsg-initialization.msgtext:"+initialization.msgtext);
with(initialization.msgtext) {
//setNewTextFormat(_global.MsgFormat);
autoSize = "left";
wordWrap = true;
multiline = true;
embedFonts = true;
selectable = false;
text = initialization.msgtext;
trace("text-initialization.msgtext:"+initialization.msgtext);
}
// set continual function to fly
//this.onEnterFrame = this.fly; //--- This does not work in actionscript
class
ScrollMsg.fly();
}
ScrollMsg.prototype.fly = function() {
trace("ScrollMsg.prototype.fly");
//if(!_global.MSG_ON_HOLD&&!_global.SYSTEM_ON_HOLD) {
trace("this._y"+this._y)
if (this._y > -800) {
this._y -=_global.MSG_SPEED;
trace("this._y"+this._y)
} else {
this.removeMovieClip();
trace("this.removeMovieClip");
}
//this._alpha = 100 - Math.abs(this._y - this.distance/2)*.3;
// }
};
Sound Class Prototype Function Losing Scope
I have the following code works great aside form the nextSound function. You'll notice that the onSoundComplete event is mapped to the nextSound method. The event fires and the nextSound function is called but the variable scope is gone.
Code:
localSound = function (container) {
this.sndIndex = 0;
this.sounds = [];
if (!(container instanceof MovieClip)) {
this.container = _root;
} else {
this.container = container;
}
};
localSound.prototype.addSound = function(soundID) {
this[soundID] = new Sound(this.container);
this[soundID].attachSound(soundID);
this[soundID].onSoundComplete = this.nextSound;
this.sounds.push(this[soundID]);
};
localSound.prototype.nextSound = function() {
if (this.sndIndex<this.sounds.length-1) {
this.sndIndex += 1;
this.sounds[this.sndIndex].start();
}
};
mySnd = new localSound();
mySnd.addSound("logonSnd");
mySnd.logonSnd.start(0, 0);
If I directly call the nextSound function:
Code:
mySnd = new localSound();
mySnd.addSound("logonSnd");
mySnd.logonSnd.start(0, 0);
mySnd.nextSound();
The next sound plays properly. So I am losing scope within the individual sound objects that are created.
How can I correctly map each sound object to it's parent class?
AS2 - Array.prototype.indexOf Inside Of A Class File
I have a old file that I am trying to convert into a new class file and it uses the below code. Flash then sends an error saying that "This statement is not permitted in a class definition.", how do I use prototypes inside class files, or can I?
Code:
Array.prototype.indexOf = function(value,fadeAmount) {
var i = 0;
var l = this.length;
var res = -1;
for (i; i<l; i++) {
if (this[i] == value) {
res = i;
createTemp(res, arr,fadeAmount);
break;
}
}
return res;
};
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
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...
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.
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.
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();
}
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();
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~
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
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.
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)
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
Prototype
Why doesn't this work with attachMovie?
Code:
MovieClip.prototype.onLoad = function() {
trace(this);
};
//
_root.attachMovie("testMC", "testMC", 1);
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?
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
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?
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
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
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);
};
};
Prototype
when do you use prototype in a function?
ive seen titles like:
navi_button.prototype.move_loop = function ()
{
}
why do you need this?
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?
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
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
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?
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);
};
};
Prototype...
Hi there,
can someone tell me what Prototype exactley is?
I guess it's something like css style sheets.
kind regards
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 ?
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
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
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.
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
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?....
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)
|