Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 11-10-2009, 06:53 PM   #1
latoyale
Member
 
latoyale's Avatar
 
Join Date: Oct 2009
Location: New York, NY
Posts: 64
Question Get an Objects name....

Good day,

I'm not sure how to trace the elements in my code since my variables are populated dynamically. I have tried to use trace(cartOrder[0]); but when I do I just get the output [object movieclip]. I want it to give me the name of the handbag. My code is
var cartOrder:Array = [];

Code:
var cartOrder:Array = [];
handbag1_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
handbag1_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
handbag2_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
handbag2_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
handbag3_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
handbag3_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);
handbag4_mc.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
handbag4_mc.addEventListener(MouseEvent.MOUSE_UP, dropIt);

function pickUp(evt:MouseEvent):void {
	var object = evt.currentTarget;
	object.startDrag();
}

function dropIt(evt:MouseEvent):void {
	var obj = evt.currentTarget;
	obj.stopDrag();
	
if (obj.hitTestObject(cart))
	{
		reply_txt.text = "Made it !!";
		cartOrder.push(obj);
		trace(cartOrder);
		
	}
	else
	{
		reply_txt.text = "Missed :(";
	}
}
latoyale is offline   Reply With Quote
Old 11-10-2009, 07:06 PM   #2
latoyale
Member
 
latoyale's Avatar
 
Join Date: Oct 2009
Location: New York, NY
Posts: 64
Default

Should DisplayObject be used instead?
latoyale is offline   Reply With Quote
Old 11-10-2009, 07:18 PM   #3
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

trace(cartOrder[0].name);
__________________
(6)
senocular is offline   Reply With Quote
Old 11-10-2009, 07:26 PM   #4
latoyale
Member
 
latoyale's Avatar
 
Join Date: Oct 2009
Location: New York, NY
Posts: 64
Default

Thanks it works.

I was just reading your posting of in 2004 about this. It's cool that you answered.

http://www.kirupa.com/forum/showthread.php?t=77861
latoyale is offline   Reply With Quote
Old 11-10-2009, 07:38 PM   #5
latoyale
Member
 
latoyale's Avatar
 
Join Date: Oct 2009
Location: New York, NY
Posts: 64
Default

How do I change it so that it returns whatever value I put into the cart? Right now I get whatever is in position 0.

I tried trace cartOrder.name & cartOrder[].name but these don't give me the right results.

Thanks
latoyale is offline   Reply With Quote
Old 11-10-2009, 08:12 PM   #6
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

Your cart is an array - it can contain multiple objects. You have to decide which objcet you want and use the correct index. 0 will give you the first. cartOrder.length - 1 will give you the last
__________________
(6)
senocular is offline   Reply With Quote
Old 11-10-2009, 08:19 PM   #7
latoyale
Member
 
latoyale's Avatar
 
Join Date: Oct 2009
Location: New York, NY
Posts: 64
Default

There is no way to get a listing from the array of whats in the cart?

What I ultimately want to do is send the 4 variables from the array to javascript. The trick is I need to know what order each item is going into the array. Which one is first, second, and so on. This way I can get a user's preference.

I am trying to use trace to see if I am on the right path track of getting this done. I figure if I can get the trace to display the contents of my array then I can dump the array values into variables, then send the individual variables into javascript.
latoyale is offline   Reply With Quote
Old 11-11-2009, 08:50 PM   #8
latoyale
Member
 
latoyale's Avatar
 
Join Date: Oct 2009
Location: New York, NY
Posts: 64
Default Viewing objects in a dynamic array

I finally figured out how to trace my objects in an array.
WARNING - Its not pretty but it works.
For anyone looking at this, I did change the format of the code.

Code:
var cartOrder:Array = [];
var counter:Number=0;

createObjListeners(); //begin

function createObjListeners() : void {
	var loop:Number = 1;
	do{
		this["handbag" + loop + "_mc"].addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
		this["handbag" + loop + "_mc"].addEventListener(MouseEvent.MOUSE_UP, dropIt);
	}while(++loop <= basketCnt);
}

function pickUp(evt:MouseEvent):void {
	var object = evt.currentTarget;
	object.startDrag();
}

function dropIt(evt:MouseEvent):void {
	var obj = evt.currentTarget;
	obj.stopDrag();
	
	

	if (obj.hitTestObject(cart))
	{
		reply_txt.text = "Made it !!";
		cartOrder.push(obj);
		counter++;
		trace(counter);
	}
	else
	{
		reply_txt.text = "Missed :(";
	}
	
	
	// Here starts my error checking
	if (counter == 1)
	{
		trace (cartOrder[0].name);
	}
	if (counter == 2)
	{
		trace (cartOrder[1].name);
	}
	if (counter == 3)
	{
		trace (cartOrder[2].name);
	}
	if (counter == 4)
	{
		trace (cartOrder[3].name);
	}

}
latoyale is offline   Reply With Quote
Old 11-11-2009, 08:56 PM   #9
latoyale
Member
 
latoyale's Avatar
 
Join Date: Oct 2009
Location: New York, NY
Posts: 64
Question Pulling variables from an array

Question...
My dynamic array has objects in it that are "undefined". However when I do a trace on the array (cartOrder[1].name, cartOrder[2].name, etc.) I can see the name of the object. Can I take an object out of the array and assign it as a new variable? Is it possible?
latoyale is offline   Reply With Quote
Old 11-11-2009, 09:07 PM   #10
latoyale
Member
 
latoyale's Avatar
 
Join Date: Oct 2009
Location: New York, NY
Posts: 64
Default

Got it.... another un-elegant solution.. I can take the name of the obj in the cart and assign to to a new variable. Seems weird to me, especially since the object is not defined. Anyway here it goes.

var newvar1 = cartOrder[0].name;

If you want to check it use:
trace("newvar1 = " + newvar1);
latoyale is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:42 PM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.