正在加载...

Klye' flash blog -> klstudio.com -> here

因为用prototype很多次,所以帖过来看看…

prototype属性和ASSetPropFlags函数至从使用as2后,所有的功能新增都是利用继承的方式撰写,但是prototype的设定并没有因此不见啰!!,下面有两个范例可以参考….
//====新增 movie clip 的位置属性 ===============
// 设定mc的get和set 位置函数
function $setLocation(pt) {
this._x = pt.x;
this._y = pt.y;
}

function $getLocation() {
return {x:this._x, y:this._y};
}

//增加mc的get和set的属性
MovieClip.prototype.addProperty("_location",$getLocation, $setLocation);
// 设定ASSetPropFlags,防止利用for(i in mc)取得讯息
var HIDDEN:Number = 1;
var PROTECT_DELETE:Number = 2;
var PROTECT_OVERWRITE:Number = 4;
ASSetPropFlags(MovieClip.prototype,"_location", HIDDEN | PROTECT_DELETE | PROTECT_OVERWRITE, 0);
//如此movie clip就可以利用_location定位了!!
my_mc._location = {x:20, y:40};

//====新增取得 movie clip 祖父层信息 ===========
// 设定mc的get和set 上两层的函数
function $setGrandpa(mc) {
this.$grandpa = mc;
}
function $getGrandpa() {
return this._parent._parent;
}
MovieClip.prototype.addProperty("_grandpa", $getGrandpa, $setGrandpa);

// 设定ASSetPropFlags,防止利用for(i in mc)取得讯息
var HIDDEN:Number = 1;
var PROTECT_DELETE:Number = 2;
var PROTECT_OVERWRITE:Number = 4;
ASSetPropFlags(MovieClip.prototype, "_grandpa",HIDDEN | PROTECT_DELETE | PROTECT_OVERWRITE, 0);
//建立两层movie clip然后测试_grandpa属性
createEmptyMovieClip("dad_mc", 0);
dad_mc.createEmptyMovieClip("sonofa_mc", 0);
trace(dad_mc.sonofa_mc._grandpa);

P.S.
文章转载处:Kyle's Flash Blog
ASSetPropFlags函数参照资料:http://www.osflash.org/doku.php?id=flashcoders:undocumented:assetpropflags

备用: 2-dim-Array
ferdymania30-10-2003, 08:00 PM
I have been having problems initliasing a 2 dimensional array…
i have declared it in my class variables..
like so..

class Board{
var gridCells:Array;
….
//then in constructor i want to
// fill the cells with -1's
for(var i=0;i<10;i++){
for(var j=0;j<10;j++){
gridCells[i][j] = -1;
trace( gridCells[i][j]);
}
}

when i do the trace i get "undefined"
Huh ????
i have tried everything… how do i declare and initialise
a 2 dimensional array ???
steve
:confused:

——————————————————————————–

ferdymania31-10-2003, 02:22 AM
stop the answers…
youre driving me mad with all your solutions…
:-)
i sorted it so stop looking..
here is how…

class Board{
var gridCells:Array;
…blah

//constructor
var hor = new Array(0,0,0,0,0,0,0,0,0,0);
gridCells = new Array(hor,hor, hor,hor,hor,hor,hor, hor,hor,hor);
..

that seemed to do the trickkk
bloody nuisance but..
and stop pestering me with your replies…!!!
steve
:D

——————————————————————————–

farafiro31-10-2003, 02:57 AM
thx for the info here freddy but

[useastags]

——————————————————————————–

ferdymania31-10-2003, 01:54 PM
thanks faffy..
didnt know about as tag…
i will use it in future…
cheers
steve :D

——————————————————————————–

Gillespie31-10-2003, 03:24 PM
This is a bit interesting for me too, considering

class Something extends SomethingElse {
public var myArray=new Array(["1","2","3"],["4","5","6"]);
function Something(){
accessArray();
};

function accessArray(){
trace(myArray);
trace(this.myArray);
// Begin crap code.
Object=new Object();
Object.something=function(){
// Neither of these work of course, but what does, apart from
// going _root.SomethingElseInstanceName.SomethingInstanceName.myArray?
trace(myArray);
trace(this.myArray);
};
};

FAQ Search Memberlist Usergroups Register Profile Log in to check your private messages Log in

declare two-dimensional array, how????

www.gotoandplay.it Forum Index -> General Actionscript
View previous topic :: View next topic
Author Message
Pandan

Joined: 11 Aug 2005
Posts: 3

Posted: Thu Aug 11, 2005 11:51 am Post subject: declare two-dimensional array, how????

——————————————————————————–

I have a funtion that let's me rotate a two-dimensional array.

The code sends a predefined array in to the funtion.
The function then makes a new two-dimensional array and puts the rearranged data into it.

The problem is that I can't figure out how to declare the new two-dimensional array(aTest2).

function rotate_90(aTest) {
var aTest2:Array = new Array()
for(i=0;i<4;++i){
for(j=0;j<4;++j) {
aTest2[j][4-1-i] = 0;
aTest2[j][4-1-i] = aTest[i][j];
}
}
printArray(aTest2);
}

Back to top

Asgar

Joined: 08 Aug 2005
Posts: 13
Location: The Netherlands
Posted: Thu Aug 11, 2005 12:57 pm Post subject:

——————————————————————————–

http://www.actionscript.org/forums/archive/index.php3/t-36979.html

Bit of an ugly solution i.m.h.o.

Doesn't this work ?

var arrTest[4][4] work ? (I'm not on a Flash installed PC right now, so I can't test it myself ^_^)

Back to top

Pandan

Joined: 11 Aug 2005
Posts: 3

Posted: Thu Aug 11, 2005 1:55 pm Post subject: Sorry that doesn't work

——————————————————————————–

The problem is that that I want the new array to be dynamic in size. So that i can set the size with parameters passed to the function.

Back to top

GhostEye

Joined: 30 Jul 2005
Posts: 12
Location: Illinois
Posted: Thu Aug 11, 2005 2:53 pm Post subject:

——————————————————————————–

well u have aTest2 as the main array that is worked with the j values. so for the I values, the second dimension of the array, u can make another array, and put that array inside aTest2.
_________________
A Fool Thinks He Knows Everything, A Wise man Knows He Knows Nothing~

If You Protect Everything, You Protect Nothing~

Back to top

Lapo
Site Admin

Joined: 24 Jun 2003
Posts: 1154
Location: Italy
Posted: Thu Aug 11, 2005 2:57 pm Post subject:

——————————————————————————–

Actionscript doesn't support the declaration of multi-dimensional arrays as you would do in C/C++/Java

While in Java you can have this:

Code:
String[][] myArray = String[10][10]

in Actionscript you can declare only one-dimension arrays. However you can add more dimensions by initializing as an array each element of the array you have just created.

In other words:

Code:

var arr:Array = new Array(10)

for (var i:Number = 0; i < arr.length; i++)
{
arr[i] = new Array(10)
}

// Set an element in the array
arr[5][5] = "hi there!"

trace(arr[5][5])

If you expand this example you can create even more complex data structures like 3d arrays etc…

hope it helps
_________________

Lapo

Back to top

Asgar

Joined: 08 Aug 2005
Posts: 13
Location: The Netherlands
Posted: Thu Aug 11, 2005 3:43 pm Post subject:

——————————————————————————–

You could try something like a linked list if you want the array to be dynamic

I'll just write down pseudo code though

Code:

class Element{
var value:whatever;
var nextElement:Element;

public function Element(){
value = <something>;
nextElement = <someElement>;
}
}

That's basically the same as 1 array entry. All you need next is a constructor which initializes the "nextElement" to null (There's no next Element yet), and a function to modify the value, and one to retrieve the value like :

Element.setValue(3);
Element.getValue();

If you create a new Element, you have 2 elements :

[El1] [El2]

You now need a function to set the "nextElement" variable of an Element to some other element like :

El1.setNextElement(El2);

Which should create something like :

[El1] –> [El2]

We got a tiny array now, and it's dynamically changed size

If you want the array to be multidimensional, you can se the value property to type Element… This way you can create an infinite number of dimensions in your array

This type of list is rather nice to check aswell, since you can use recursion :

theElement = Element;
while(theElement.getValue() != null){
theElement = theElement.getNextElement();
}

I hope that helps, it's kind of hard to understand when it's the first time you're using it, but quite handy indeed

Back to top

Pandan

Joined: 11 Aug 2005
Posts: 3

Posted: Fri Aug 12, 2005 5:15 pm Post subject: Thx!

——————————————————————————–

Thanks alot for the tips. It's gonna help alot!

Back to top

Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

www.gotoandplay.it Forum Index -> General Actionscript All times are GMT + 1 Hour

Page 1 of 1

Jump to: Select a forum Feedback—————-Feedback Community—————-BookmarkDickDynamiteSubmitted Games FlashGaming—————-General ActionscriptGameDevThe Multiplayer Central { New! }PrototypesBetatestServer SideActionscript alternativesGraphix and Motion

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB 2.0.17 © 2001, 2002 phpBB Group

http://www.gotoandplay.it/_forums/viewtopic.php?t=1366

还没找到您要的东西?Google试试看吧,
Google更注重原创、时效性好的文章:


本文相关评论: 才 5 条评论
  1. N神 2005-08-13 05:49:04

    学2.0吧。ASSetPropFlags已成浮云了。。

  2. aw 2005-08-13 06:57:02

    没时间学啊,要不你教我,呵呵

  3. click the up coming post 2013-04-28 02:26:32

    click the up coming post…

    [转载]prototype属性和ASSetPropFlags琐碎…

  4. buy twitter followers uk real 2014-05-19 11:38:28

    buy twitter followers

    [转载]prototype属性和ASSetPropFlags琐碎

  5. teenyweenyurl.com 2014-09-21 10:34:58

    teenyweenyurl.com

    [转载]prototype属性和ASSetPropFlags琐碎

[支持Ctrl+Enter]为了我们大家和家人的安全,留言请慎重!
声明:
1、本站仅与见过面的个人博客交换链接,见此文
2、留言时的头像是Gravatar提供的服务。如果您有兴趣并且有闲暇时间,可以看看这里的介绍