View comments | RSS feed

ActionScript 2.0 Language Reference

This book describes the elements of the ActionScript programming language.


Version 8

Comments


No screen name said on Oct 31, 2005 at 7:42 AM :
Does anyone really know how to link a drawn movieclip from the library with an classfile.as?

tryed many things, some worked but i do not know what the correct way to do so is.

Roy
roygarnaat@hotmail.com
No screen name said on Nov 4, 2005 at 6:25 AM :
Roy, this is the method I use.

// this function allows the dynamic association of classes with movieclip instances
// class should be a subclass of MovieClip so that it inherits _x, _y, etc.
// you must always cast the return from this function though as attachMovie returns a MovieClip instance regardless of class association
// use with empty library symbol instead of createEmptyMovieClip for associating "empty" mcs with a class
public static function attach(a_mc_parent:MovieClip, a_str_linkageID:String, a_str_name:String, a_int_level:Number, a_obj_initObject:Object, a_fnc_class:Function, a_fnc_callback:String, a_arr_args:Array):Object
{
// associate the library symbol with the provided class
Object.registerClass(a_str_linkageID, a_fnc_class);
// attach the symbol
var mc:Object = a_mc_parent.attachMovie(a_str_linkageID, a_str_name, a_int_level, a_obj_initObject);
// if a method of the new class was specified, call it
if(a_fnc_callback != null)
{
mc[a_fnc_callback].apply(mc, a_arr_args);
}
// de-associate the library symbol with the provided class
Object.registerClass(a_str_linkageID, null);
// return a ref to the new mc/class instance
return mc;
}

Sample usage:

var myClip:MyClass = MyClass(Application.attach(_root, "mySymbol", "myNewClip", _root.getNextHighestDepth(), {_x: 10, _y: 10}, MyClass, "myClassInitFunction", [arg1, arg2]);
No screen name said on Nov 10, 2005 at 8:15 AM :
This doesn't works...

var 2dArray:Array = new Array(new Array(6), new Array(6));

just creates an 2d Array with lenght 2 in both dimensions...
svnah said on Nov 23, 2005 at 6:38 AM :
k, here's the code u need - done this many times - as2.0 is a bit picky when making a multiple dimension array - first u have to declare the contents of the single internal arrays - then encapsulate the children into a larger multi-dimesional array... Either that or create a class - but i find this easier and faster...

var meat = new Array(7);
var bread = new Array(10);
var potgrl = new Array(6);
var frtdry = new Array(11);
var bev = new Array(7);
var cereal = new Array(8);
var condmnts = new Array(6);
var arrStats = new Array();
var choices = new Array(meat,bread,potgrl,frtdry,bev,cereal,condmnts);

i used this to create an array to keep track of student's picks from the various food groups when creating a meal plan for breakfast...

hope this helps,
Dawn
No screen name said on Dec 18, 2005 at 10:11 PM :
I'm writing a real-time strategy game in flash, and the best (maybe only) way for me to execute a lot of my enemy finding code is to use for..in loops by iterating through an array of potential enemies and seeing which fall into the range of the character. Anyways, I've been getting errors when trying this, saying that the only class that can iterated on is the String class. Why this is the only one, I don't know, but is there any way that I can iterate over any object (or in this instance an Array object)?
pan69 said on Dec 27, 2005 at 9:38 PM :
To "no screen name":

The reason herefore is that the for...in interator is always a string. You are iterating through an objects property "names", which are stings. This is because all objects in ActionScript 2.0 and below are associative arrays.

Just look at this syntax:

for(var s : String in someObject)
{
// whatever.
}

[Can you please in the future post questions like this on a normal forum site, like actionscript.org? The comments placed here are meant to be comment on livedocs only]
EliteMX said on Dec 29, 2005 at 4:41 PM :
//Small Arrays

function create2DArray(width:Number, height:Number):Array {
var array:Array = Array();
for(var index:Number = 0; index < width; ++index)
array.push(Array(height));
return array;
}

var smallArray:Array = create2DArray(50, 50);
smallArray[0][0] = "First Element";
smallArray[49][49] = "Last Element";
trace(smallArray[0][0]+"\r"+smallArray[49][49]);


//Large Arrays
function setValue(obj:Object, x:Number, y:Number, value):Void {
if(obj != undefined) {
if(obj[x] == undefined || typeof(obj[x])!=Object)
obj[x] = Array();
obj[x][y] = value;
}
}
function getValue(obj:Object, x:Number, y:Number) {
return obj[x][y];
}

var acObj:Object = new Object();
setValue(acObj,0,0,"First Object");
setValue(acObj,10000,100000,"Another Object");
trace(getValue(acObj,0,0)+"\r"+getValue(acObj,10000,100000));
Psyboyo said on Jan 10, 2006 at 2:03 AM :
Im sorry, I'm not following the discussion, BUT something caught my eye: var 2dArray:Array = new Array() is WRONG.

"2dArray" is an illegal name for a flash element: names cannot start with a number. Good luck.
shimi2 said on Jan 26, 2006 at 10:35 AM :
PDF documentation is available at:
http://www.macromedia.com/support/documentation/en/flash/
Migs Davis said on Apr 19, 2006 at 8:50 PM :
Is there any function to return the instance name of an object placed at authoring time as a string?
Jackie_2004 said on Sep 17, 2006 at 6:16 PM :
hello guys! i have been having this problem... i have three movieclips on the stage and also i am loading a mc using code:
target.attachMovie("back1", "ltc", target.getNextHighestDepth(), {_x:0, _y:0});

and what i want with the movieclip is to send it to the background using this code:
mx.behaviors.DepthControl.sendToBack(target["ltc"]);

the problem is that flash doesnt send the mc to the back, is there any problem with the DepthControl? or why it is not sent? any ideas?
1pat2 said on Oct 5, 2006 at 6:23 AM :
I wanted to know if anyone can help me correct a action script error.

**Error** Scene=Scene 1, layer=Layer 1, frame=56:Line 1: Wrong number of parameters; gotoAndPlay requires between 1 and 2.
gotoAndPlay();
Rob_QVC said on Oct 23, 2006 at 11:17 AM :
When it comes to arrays I am mostly clueless, I created a function that I think pushes a variable into an array. The varable is a movieclip from the library. What I need to knwo is if I can call myarray[0] and have it appear somwhere else.

btnUp.onRelease = function():Void {

var grp1:MovieClip = test.attachMovie("Group1", "star", 1);
myarray.push(grp1);

};
ragtoproy said on Oct 26, 2006 at 11:05 AM :
Hello All!
I was wondering if anyone knows the proper code for loading (and
playing) a SWF video file at a precise location (say x=100 y=150) when
a button is clicked? The button is named 411_btn and the SWF file
(which is not in the library) is named 411Page.SWF. (If necessary I can
convert the 411Page.SWF file into a flv file and put it in the library-I
would call it 411Page_mc and give it a linkage identifier of 411Page)
Also;
How do I get that video to play on a certain layer? The video needs to be
behind the main layer (and without a skin). Any help would be greatly
appreciated!!! I can also email the files to you if needed! Thanks!!!!!
I cannot find the answer to this in ANY of the documentation....
No screen name said on Nov 13, 2006 at 12:24 PM :
2 separate Questions:

I have a dynamic text which shows the answer and it does not remove the dynamic at all

reset.onRelease = function() {
removeMovieClip("mathBottom1");
removeMovieClip("mathBottom2");
//loads up the movie file to show the correct number using the dot
//loads up all of the numbers
//loads up the array to realte to the numbers
numberList1 = new Array["circle0", "circle1", "circle2", "circle3", "circle4", "circle5", "circle6", "circle7", "circle8", "circle9"]();
numberList2 = new Array["circle0", "circle1", "circle2", "circle3", "circle4", "circle5", "circle6", "circle7", "circle8", "circle9"]();
//function that generates a whole number between the range min and max
function generateNumber(min:Number, max:Number):Number {
return (Math.floor(Math.random()*(max-min+1)+min));
}
myFirstNum = generateNumber(0, 9);
mySecondNum = generateNumber(0, 9);
//picks out the generated number between one and three
numberOfResults = generateNumber(1, 3);
//shows the text onto the actual site
//the total number of both the first number and the second number
total = (myFirstNum+mySecondNum);
firstNum.text = myFirstNum;
secondNum.text = mySecondNum;
//loads up the text generator
myText = Array["Good Job", "Wonderful", "That is Correct"]();
enterNum.onRelease = function() {
trace("the input "+inputNum.text);
//converts number into a text number
myInputNum = Number(inputNum.text);
if (myInputNum == myFirstNum+mySecondNum) {
trace("random text number2 "+numberOfResults);
showText.text = myText[numberOfResults]+"The number is "+myInputNum;
} else {
//creating the movie to load up the numbers
createEmptyMovieClip("mathBottom1", 50);
mathBottom1._x = 613.0;
mathBottom1._y = 147.5;
//set the size down to the appropriate scale
mathBottom1._xscale = 50;
mathBottom1._yscale = 50;
//retrieves the random movie number being loaded up from the array, movieLoad1 is an empty movie clip reserving for the site
mathBottom1.attachMovie("circle"+myFirstNum, "movieLoad11", this);
secondDelay = setInterval(this, "circle"+myFirstNum, myFirstNum*1000);
//second part of the file
createEmptyMovieClip("mathBottom2", 70);
//set the size down to the appropriate scale
mathBottom2._xscale = 50;
mathBottom2._yscale = 50;
//set the movie links into a file
mathBottom2._x = 613.0;
mathBottom2._y = 380.4;
//attach movie
mathBottom2.attachMovie("circle"+mySecondNum, "movieLoad21", this);
//generates the numbers
correctAns.text = total;
//sets the
setInterval(correctAns, 1000);
}
};
};

The second question is that is there a way to slow down a movie clip in seconds if it is animated...
chris5678 said on Dec 11, 2006 at 4:16 AM :
I am setting up a Flash 8 ecommerce site with payment via PayPal.
One of the variables that goes to PayPal is named 'return' and cannot be changed.
This is a keyword or reserved word in Flash.
How can I send this keyword as a variable in a named value pair.
If you can sort this out I'll send you a packet of Mince Pies.
Thanks
Chris
No screen name said on Dec 14, 2006 at 7:20 AM :
speed = 14;
imageMask.onEnterFrame = function() {
if ((this._width+this._x)<_xmouse) {
if (this._width+this._x>=_xmouse-0.8 || this._width+this._x == _xmouse) {
this._x = _xmouse-this._width;
} else {
this._x += (_xmouse-(this._width+this._x))/speed;
}
} else if ((this._width+this._x)>_xmouse) {
if ((this._width+this._x)<=_xmouse+0.8 || (this._width+this._x) == _xmouse) {
this._x = _xmouse-this._width;
} else {
this._x -= ((this._width+this._x)-_xmouse)/speed;
}
} else {
this._x = _xmouse-this._width;
}
};
stop(); // Why stop() ?? what does stop ? and no stop is not working?!
ladytechie1 said on Mar 17, 2007 at 8:05 AM :
I am wondering if it is possible to have actionscript check for whether a link is on the website itself that the SWF file is on prior to displaying anything? I am very stumped on how to check for this.
No screen name said on May 23, 2007 at 7:51 AM :
i was wondering if it is possible to track the position along a dynamically drawn line. for example, if the user were to drag a movie clip over a line, is it possible to track where along the line that movie clip is.
i am trying to create a program in which one can draw a circuit and drag resistors, switches, etc. onto it and calculate the voltages and currents along it. so is there a way to track the position, or at least the order in which certain movie clips are located along a line.
timheath said on Jun 5, 2007 at 5:52 AM :
Does anyone know how to do a "drag and rotate" on a movieclip using actionscript? I have it rotating, but the object jumps to where the mouse is when the user clicks...is there a work around for this? I've probably done every single thing I could think of and I'm at a loss. Here's my code:

outerRing.onPress = function()
{
outerRing.onMouseMove = function()
{
var distX:Number = this._x-this._parent._xmouse;
var distY:Number = this._y-this._parent._ymouse;
var radians:Number = Math.atan2(distY, distX);
targetRotation = ((radians/Math.PI)*180);
this._rotation = targetRotation;
};
};
outerRing.onMouseUp = function()
{
if (_root.outerRing.onMouseMove)
{
delete _root.outerRing.onMouseMove;
}
};
No screen name said on Jun 11, 2007 at 2:36 PM :
can you please explain in greater detail what you mean by 'drag and rotate'

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flash/8/main/Part4_ASLR2.html