Log in

View Full Version : Using arrays to display objects



evan
07-28-2008, 09:04 PM
typically I have been doing stuff like this


//This adds a custom cursor quick and dirty
circle_mc.addEventListener(MouseEvent.CLICK,showThis);
function showThis(evt:MouseEvent):void
{
var circ:MovieClip = new Circ ();
addChild (circ);
Mouse.hide();
circ.x=mouseX
circ.y=mouseY
circ.startDrag(true);

}


}

to display mcs on events

now I really want to make the jump to arrays big time.

This code is a trainwreck but I hope I can demostrate what I'm trying to do in AS 3

var cursorSwap:String = new String();
var i:Number;
var cursorArray:Array = new Array(

[my_mc.circle, "circle"],
[my_mc.circle, "square"],
[my_mc.circle, "diamond"])

circle_mc.addEventListener(MouseEvent.CLICK,circleSwap);
square_mc.addEventListener(MouseEvent.CLICK,squareSwap);
diamond_mc.addEventListener(MouseEvent.CLICK,diamondSwap);

function circleSwap(evt:MouseEvent):void
{Mouse.hide();
//cursors.circle.startDrag();
for(i=0; i<cursorArray.length; i++);
cursorSwap = cursorArray[this.id][1];
circle.x =mouseX;
circle.y =mouseY;



}

What I really want to learn how to do is call items either from the library,
a frame in a movieclip and either just diplay them or drag them around as with a cursor.

Most demos I see handle DATA, or just return a string using "trace" I get that but I wish I could see stuf that is more visual.

Medyman
07-29-2008, 01:57 PM
Are you trying to do something similar to my very first example (http://www.visualbinary.net/files/tutorials/toolbar/) -- but in AS3?

evan
07-29-2008, 02:23 PM
Somewhat,


because:

var circ:MovieClip = new Circ ();
addChild (circ);
circ.x=-100
circ.y=-100

circle_mc.addEventListener(MouseEvent.CLICK,showIt, false, 0, true);
function showIt(evt:MouseEvent):void
{

pad.addEventListener(MouseEvent.ROLL_OVER,showThis, false, 0, true);

}



function showThis(evt:MouseEvent):void
{
Mouse.hide();
circ.alpha=(1);
circ.x=mouseX
circ.y=mouseY
circ.startDrag(true);

pad.addEventListener(MouseEvent.ROLL_OUT,hideThis, false, 0, true);
function hideThis(evt:MouseEvent):void
{
Mouse.show();
circ.alpha=0;
}


}

works well -but 12 times or so -not cool

such is why I ask.


So, I'm also revisiting "wise words".


and looking at some postings here having to do with xml.

If you have the time though -yeah it would be cool to see a demo of the way that array called mc from frames of another mc -in AS3.

Any sugested links or tutorials also?

evan
07-29-2008, 05:34 PM
Are you trying to do something similar to my very first example -- but in AS3?


Mendyman,
If you have the time to show me a "mini-version" of how the cursor change code works in AS3 it would be huge.

I DO have an AS3 version that works -just without the arrays -all it means is that I have separate functions for each button to target a frame in the "cursor" mc. It works. but it's not as cool.

using one mc to store all the icons is the best way
there are other ways like swap out mcs with booleans and else if statements but it's not as straight forward.