Be a Supporter!

Accessing Items From A Movieclip

  • 446 Views
  • 14 Replies
New Topic Respond to this Topic
Computoguy
Computoguy
  • Member since: Dec. 11, 2010
  • Offline.
Forum Stats
Member
Level 02
Game Developer
Accessing Items From A Movieclip Apr. 21st, 2012 @ 11:34 AM Reply

Alright guys, heres the problem. I want to access something thats on the stage, from a movieclip. This used to work for me:

MovieClip(root).ItemName.whatIWantItToDo

Now, it doesn't work anymore, probably because of some sort of update. What do I use now?
(Yes, I have Googled it.)

maringtr
maringtr
  • Member since: Sep. 16, 2011
  • Offline.
Forum Stats
Member
Level 03
Programmer
Response to Accessing Items From A Movieclip Apr. 21st, 2012 @ 11:53 AM Reply

Can you paste your exact code?

maringtr
maringtr
  • Member since: Sep. 16, 2011
  • Offline.
Forum Stats
Member
Level 03
Programmer
Response to Accessing Items From A Movieclip Apr. 21st, 2012 @ 11:59 AM Reply

Are you sure you're using the correct instance name and that the given instance has the property/method you're trying to access?

Computoguy
Computoguy
  • Member since: Dec. 11, 2010
  • Offline.
Forum Stats
Member
Level 02
Game Developer
Response to Accessing Items From A Movieclip Apr. 21st, 2012 @ 12:12 PM Reply

At 4/21/12 11:59 AM, maringtr wrote: Are you sure you're using the correct instance name and that the given instance has the property/method you're trying to access?
import flash.events.MouseEvent;

var cankeybedragged:Boolean = false;

keyininventory.visible = false;

****MovieClip(root).keyforinventory.addEventListener(MouseEvent.CLICK, checkifkeydraggable);****

function checkifkeydraggable(event:MouseEvent):void{
	if(cankeybedragged){
		keyininventory.addEventListener(MouseEvent.MOUSE_DOWN, dragkey);
		keyininventory.addEventListener(MouseEvent.MOUSE_UP, nodragkey);
	}
}

function dragkey(event:MouseEvent):void{
	keyforinventory.startDrag();
}

function nodragkey(event:MouseEvent):void{
	keyforinventory.stopDrag();
}

I am 100% sure that it's the right instance name.

Paranoia
Paranoia
  • Member since: Apr. 22, 2005
  • Offline.
Forum Stats
Member
Level 35
Game Developer
Response to Accessing Items From A Movieclip Apr. 21st, 2012 @ 01:38 PM Reply

At 4/21/12 12:12 PM, Computoguy wrote:
At 4/21/12 11:59 AM, maringtr wrote: Are you sure you're using the correct instance name and that the given instance has the property/method you're trying to access?
import flash.events.MouseEvent;

var cankeybedragged:Boolean = false;

keyininventory.visible = false;

****MovieClip(root).keyforinventory.addEventListener(MouseEv ent.CLICK, checkifkeydraggable);****

function checkifkeydraggable(event:MouseEvent):void{
if(cankeybedragged){
keyininventory.addEventListener(MouseEvent.MOUSE_DOWN, dragkey);
keyininventory.addEventListener(MouseEvent.MOUSE_UP, nodragkey);
}
}

function dragkey(event:MouseEvent):void{
keyforinventory.startDrag();
}

function nodragkey(event:MouseEvent):void{
keyforinventory.stopDrag();
}

I am 100% sure that it's the right instance name.

So what happens when you run your code, and what do you want to happen? Also, you can work out what's going on based on a few traces.

function checkifkeydraggable(event:MouseEvent):void{
	trace(keycanbedragged);
	if(cankeybedragged){
		keyininventory.addEventListener(MouseEvent.MOUSE_DOWN, dragkey);
		keyininventory.addEventListener(MouseEvent.MOUSE_UP, nodragkey);
	};
};

should return 'false', based on what you've posted, but if something's going wrong elsewhere then nothing will happen.


BBS Signature
Computoguy
Computoguy
  • Member since: Dec. 11, 2010
  • Offline.
Forum Stats
Member
Level 02
Game Developer
Response to Accessing Items From A Movieclip Apr. 21st, 2012 @ 01:41 PM Reply

I want it to drag an item in the inventory. The problem is, when I say MovieClip(root), it doesnt work. I want to access keyforinventory. This used to work: MovieClip(root).keyforinventory. Now, it says it can't find it, when I KNOW it's there, and that its its instance name. >:/

Jin
Jin
  • Member since: Sep. 9, 2006
  • Offline.
Forum Stats
Supporter
Level 48
Blank Slate
Response to Accessing Items From A Movieclip Apr. 21st, 2012 @ 01:55 PM Reply

// If you can do this:
keyininventory.visible = false;

// Then you can also do this:
keyforinventory.addEventListener(MouseEvent.CLICK, checkifkeydraggable);

BBS Signature
Computoguy
Computoguy
  • Member since: Dec. 11, 2010
  • Offline.
Forum Stats
Member
Level 02
Game Developer
Response to Accessing Items From A Movieclip Apr. 21st, 2012 @ 02:05 PM Reply

keyforinventory is not IN the movieclip, thats what this posts about. MovieClip(root) used to work but now it doesnt.

maringtr
maringtr
  • Member since: Sep. 16, 2011
  • Offline.
Forum Stats
Member
Level 03
Programmer
Response to Accessing Items From A Movieclip Apr. 22nd, 2012 @ 02:48 AM Reply

If you don't mind sending me your FLA file, I'd be happy to help you out. I'm sure it's an easy fix, but I need to see how you FLA is structured.

maringtr
maringtr
  • Member since: Sep. 16, 2011
  • Offline.
Forum Stats
Member
Level 03
Programmer
Response to Accessing Items From A Movieclip Apr. 22nd, 2012 @ 02:49 AM Reply

*your FLA

Bad typo :)

Computoguy
Computoguy
  • Member since: Dec. 11, 2010
  • Offline.
Forum Stats
Member
Level 02
Game Developer
Response to Accessing Items From A Movieclip Apr. 22nd, 2012 @ 03:38 PM Reply

At 4/22/12 02:49 AM, maringtr wrote: *your FLA

Bad typo :)

http://www.mediafire.com/?f2bzwvg2daz9x3q

There you go. :)

maringtr
maringtr
  • Member since: Sep. 16, 2011
  • Offline.
Forum Stats
Member
Level 03
Programmer
Response to Accessing Items From A Movieclip Apr. 23rd, 2012 @ 10:14 AM Reply

Hey,

My apologies but the machine I'm currently on has CS5 and you saved the file in CS5.5. Can you export the file in an older format, so I can open it up?

I'll have access to a CS5.5 machine later today and check it out, but if you can do the export - that would speed things up.

Computoguy
Computoguy
  • Member since: Dec. 11, 2010
  • Offline.
Forum Stats
Member
Level 02
Game Developer
Response to Accessing Items From A Movieclip Apr. 24th, 2012 @ 05:39 PM Reply

At 4/23/12 10:14 AM, maringtr wrote: Hey,

My apologies but the machine I'm currently on has CS5 and you saved the file in CS5.5. Can you export the file in an older format, so I can open it up?

I'll have access to a CS5.5 machine later today and check it out, but if you can do the export - that would speed things up.

http://www.mediafire.com/?k2tyrf0ktephye0

Computoguy
Computoguy
  • Member since: Dec. 11, 2010
  • Offline.
Forum Stats
Member
Level 02
Game Developer
Response to Accessing Items From A Movieclip Apr. 28th, 2012 @ 03:10 PM Reply

Can someone please help me?

Computoguy
Computoguy
  • Member since: Dec. 11, 2010
  • Offline.
Forum Stats
Member
Level 02
Game Developer
Response to Accessing Items From A Movieclip May. 3rd, 2012 @ 11:41 AM Reply

Please? Anyone there to help? <:/