00:00
00:00
Newgrounds Background Image Theme

Care2mchBEAR just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Accessing Items From A Movieclip

702 Views | 14 Replies
New Topic Respond to this Topic

Accessing Items From A Movieclip 2012-04-21 11:34:30


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.)

Response to Accessing Items From A Movieclip 2012-04-21 11:53:33


Can you paste your exact code?

Response to Accessing Items From A Movieclip 2012-04-21 11:59:41


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

Response to Accessing Items From A Movieclip 2012-04-21 12:12:38


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.

Response to Accessing Items From A Movieclip 2012-04-21 13:38:02


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

Response to Accessing Items From A Movieclip 2012-04-21 13:41:31


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. >:/

Response to Accessing Items From A Movieclip 2012-04-21 13:55:45


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

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

If you're a Newgrounds OG who appreciates Flash games with depth, check out the game I made in 2024.

Response to Accessing Items From A Movieclip 2012-04-21 14:05:23


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

Response to Accessing Items From A Movieclip 2012-04-22 02:48:21


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.

Response to Accessing Items From A Movieclip 2012-04-22 02:49:21


*your FLA

Bad typo :)

Response to Accessing Items From A Movieclip 2012-04-22 15:38:06


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

Bad typo :)

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

There you go. :)

Response to Accessing Items From A Movieclip 2012-04-23 10:14:26


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.

Response to Accessing Items From A Movieclip 2012-04-24 17:39:37


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

Response to Accessing Items From A Movieclip 2012-04-28 15:10:47


Can someone please help me?

Response to Accessing Items From A Movieclip 2012-05-03 11:41:01


Please? Anyone there to help? <:/