PDA

View Full Version : problems with passing parameters and arrays---- please help :s


Crazy_Flash_Man
07-16-2006, 08:10 PM
Hello everyone!
I'm kinda new to actionscript programming and currently i'm making a very small photo album. in this photo album, i have thumbnails and a main view area. i have actually achieved making it but the coding i have done is not really suitable.. like it's very long.. i'm trying to use arrays to achieve the same task which results in shorter coding.

well first, here is the code i programmed firstly which works perfectly:

///////////////////////////////////////////////
var opened:Object = new Object();
var top:Number;

// "mc1..2..3" are the pictures in the library
// "f1...2...3" are shapes where the pictures are set to their positions/scales

this.attachMovie("mc1","mc1",this.getNextHighestDepth());
mc1._height= f1._height;
mc1._width= f1._width
mc1._x= f1._x;
mc1._y= f1._y;
this.attachMovie("mc2","mc2",this.getNextHighestDepth());
mc2._height= f2._height;
mc2._width= f2._width;
mc2._x= f2._x;
mc2._y= f2._y;
this.attachMovie("mc3","mc3",this.getNextHighestDepth());
mc3._height= f3._height;
mc3._width= f3._width;
mc3._x= f3._x;
mc3._y= f3._y;
this.attachMovie("mc4","mc4",this.getNextHighestDepth());
mc4._height= f4._height;
mc4._width= f4._width;
mc4._x= f4._x;
mc4._y= f4._y;
this.attachMovie("mc5","mc5",this.getNextHighestDepth());
mc5._height= f5._height;
mc5._width= f5._width;
mc5._x= f5._x;
mc5._y= f5._y;
this.attachMovie("mc6","mc6",this.getNextHighestDepth());
mc6._height= f6._height;
mc6._width= f6._width;
mc6._x= f6._x;
mc6._y= f6._y;

//user clicks on the thumbnail to view enlarged picture.

mc1.onRelease= function(): Void {

view("mc1");
};
mc2.onRelease= function(): Void {

view("mc2");
};
mc3.onRelease= function(): Void {

view("mc3");
};
mc4.onRelease= function(): Void {

view("mc4");
};
mc5.onRelease= function(): Void {

view("mc5");
};
mc6.onRelease= function(): Void {

view("mc6");
};



function view (slink:String):Void {


if (opened[slink] != undefined ) {
opened[slink].swapDepths(top);
return;
}
var index:Number = this.getNextHighestDepth();
var mcPic:MovieClip = this.attachMovie(slink, "mcPic"+ index, index);
opened[slink]=mcPic;
top=index;

//mcView is a simple shape where the picture is positioned and scaled on it

mcPic._height= mcView._height;
mcPic._width= mcView._width;
mcPic._x= mcView._x;
mcPic._y= mcView._y;

}

///////////////////////////////

well.. i hope my comments help you there to understand the code. sorry i'm not very used to commenting my codes lol as i'm new to flash.

as you can see the code "above" is very repetative so i thought i could use arrays to short it down.

the following is the new code i been working on, which partly works. the part that works is the thumbnails.. but when i click on them..nothing happens :s .. i'm not sure how to send an array of parameters to the function "view()"... please help:

/////////////////////////////////////////////////////

var opened:Object = new Object();
var top:Number;
var myPics:Array = new Array("mc1", "mc2", "mc3", "mc4", "mc5", "mc6");
var myArray:Array= new Array(f1, f2, f3, f4, f5, f6);


for (var i:Number=0; i< myPics.length; i++){
var mc:MovieClip = this.attachMovie(myPics[i], "mc"+ i, i);
var mov:Array= new Array (mc0, mc1, mc2, mc3, mc4, mc5);
mov[i]._height= myArray[i]._height;
mov[i]._width= myArray[i]._width;
mov[i]._x= myArray[i]._x;
mov[i]._y= myArray[i]._y;

mov[i].onRollOver= function():Void {
this._alpha=70;
};
mov[i].onRollOut= function():Void {
this._alpha=100;
};
///// everything works fine up to here//////////

mov[i].onRelease= function(): Void {

////i'm pretty sure this is where the problem is----->> view(mov[i])
view (mov[i]);
};

}

//// in here consider --->>slink:MovieClip .... should i be using a diff var type?

function view (slink:MovieClip):Void {
mcPic.removeMovieClip();
if (opened[slink] != undefined ) {
opened[slink].swapDepths(top);
return;
}

var index:Number = this.getNextHighestDepth();
var mcPic:MovieClip = this.attachMovie(slink, "mcPic"+ index, index);
opened[slink]=mcPic;
top=index;

mcPic._height= mcView._height;
mcPic._width= mcView._width;
mcPic._x= mcView._x;
mcPic._y= mcView._y;
}

////////////

any small help would be a great help to me.. I'd really really appreciate it

thanks

MichaelxxOA
07-16-2006, 09:39 PM
Depending on the relationship of the code to your data, you could possibly condense this down to this (I'm sure even more, but I'm kind of short on time).


var opened:Object = new Object ();
var top:Number;

// only necessary if you need to refer to these mc's as a group later on after the createMCs function
var mcs:Array = new Array ();
function createMCs (howMany:Number):Void
{
var i:Number;
for (i = 0; i < howMany; i++)
{
var mc:MovieClip = this.attachMovie ("mc", "mc1", this.getNextHighestDepth ());
mc._height = this["f" + i]._height;
mc._width = this["f" i]._width;
mc._x = this["f" + i]._x;
mc._y = this["f" + i]._y;

mc.onReleaseData = "mc" + i;

mc.onRelease = function ():Void
{
view (this.onReleaseData);
};

// only necessary if you need to refer to these mc's as a group later on after this function
mcs.push (mc);
}
}
function view (slink:String):Void
{
if (opened[slink] != undefined)
{
opened[slink].swapDepths (top);
return;
}
var index:Number = this.getNextHighestDepth ();
var mcPic:MovieClip = this.attachMovie (slink, "mcPic" + index, index);
opened[slink] = mcPic;
top = index;
//mcView is a simple shape where the picture is positioned and scaled on it
mcPic._height = mcView._height;
mcPic._width = mcView._width;
mcPic._x = mcView._x;
mcPic._y = mcView._y;
}

Crazy_Flash_Man
07-17-2006, 09:14 AM
HEY MAN.. SEROIUSLY .. THANKS HEAPS.. IT'S WORKING PERFECT..

that "this.onReleaseData" helped me bigtime.. where did u find "onReleaseData" lol it didnt even change color when i put it in lol