accessing a variable in a movieclip from external class

FLASH

    Next

  • 1. multiple text fields one xml document
    hey everyone. I want to be able to have one xml document that parses text into different text fields in flash. example: in xml have <about> about text goes here<about/> then in flash have a text field called about that pulls the text from that one section of the xml doc. their would be multiple sections of this xml doc. thanks! -m
  • 2. rotate function.
    Hi, Hope all are doing great! :) I was just wondering is there any way to have a mc rotate a few times and then stop at the required angle. Right now I am using _root.spinMe_mc._rotation += (80 - _rotation)/3 to make it go to angle 80 and ease a little while doing so and it works fine. However, I would like to spin it a few times before it actually goes and stops at its destination. Any help would be really great! Thanks, -a.

Re: accessing a variable in a movieclip from external class

Postby BlueD » Fri, 17 Feb 2006 00:16:31 GMT



yes. I put a trace in the function in the movieclip and apparently is 
not called.

Similar Threads:

1.accessing a variable in a movieclip from external class

Hi folks, I have a problem with scope.

I'm writing a little application to run a course, and the engine creates 
the navigation menu putting labels in the button etc...

So, as far as I change things like a dynamic text that's on the stage 
with something like

mybutton.itemText.text = 
my_xml.childNodes[0].childNodes[index-1].attributes["Label"];

this works, but what If I want to change a variable declared in the button?

I would like to retrieve from an XML the movie I want to load pressing 
this particular button, but seems like the scope of the "designed" 
objects and the programmed object is a little different, since with

in the button movieclip
************************
var myMovieDelegate:String = new String();
var selectedButton:Boolean = new Boolean();
-------------------------------------------
in the engine Class

mybutton.myMovieDelegate(my_xml.childNodes[0].childNodes[index-1].attributes["MovieToLoad"]);
------------------------------------------

this doesn't works, as doesn't works creating a function in the button 
to set the variable like

function setMovieDelegate(movie:String):Void {
	myMovieDelegate = movie;
}

Where's the problem?

2.accessing a variable in a movieclip from external class

blemmo wrote:
> Do you have this code in an onLoad Event? If so, try absolute paths, because 
> 'this' in the Event refers to the loading object, so 'mybutton' would be 
> searched in the scope of that object.
>  So it should be something like _root.mybutton.myMovieDelegate(...).
> 
>  Does this help?

mmm... so why doesn't works right now?

ok, let's try this...

--------------

class courseEngine {
	public var addEventListener:Function;
	public var removeEventListener:Function;
	private var dispatchEvent:Function;
	
	private var ayudaOpen:Boolean = new Boolean();
	
	function courseEngine() {
		mx.events.EventDispatcher.initialize(this);
		ayudaOpen = false;
	}
	
	public function initMenu(drawInIt:MovieClip, my_xml:XML) {
		drawInIt.attachMovie("mcMenuUpBorder", "upBorder", 
drawInIt.getNextHighestDepth());
		drawInIt.attachMovie("mcMenuUnit", "menuMC1", 
drawInIt.getNextHighestDepth(), {_x:0, _y:13});
		initButton(drawInIt.menuMC1, my_xml, 1);
		for (var i:Number = 2; 
i<=my_xml.childNodes[0].attributes["NumberOfItems"]; i++) {
			drawInIt.menuMC1.duplicateMovieClip("menuMC"+i, i);
			var pippo:String = new 
String(my_xml.childNodes[0].childNodes[i-1].attributes["Label"]);
			trace(drawInIt["menuMC"+i]);
			_root.drawInIt["menuMC"+i].setMovieDelegate(pippo);
			initButton(drawInIt["menuMC"+i], my_xml, i);
			drawInIt["menuMC"+i]._y = 
drawInIt["menuMC"+(i-1)]._y+drawInIt["menuMC"+(i-1)].mcGreenBox._height;
		}
		var u:Number = new 
Number(my_xml.childNodes[0].attributes["NumberOfItems"]);
		drawInIt.attachMovie("mcMenuUnderBorder", "downBorder", 
drawInIt.getNextHighestDepth(), {_x:0, _y:u*35+13});
		var myDropFilter = new flash.filters.DropShadowFilter();
		var myFilters:Array = drawInIt.filters;
		myFilters.push(myDropFilter);
		drawInIt.filters = myFilters;
	}
	private function initButton(button:MovieClip, my_xml:XML, index:Number) {
		button.itemText.text = 
my_xml.childNodes[0].childNodes[index-1].attributes["Label"];
		if (button.itemText.textHeight<16) {
			button.itemText._y = button.itemText._y+6;
			button.itemText._height = 16;
		}
	}
	public function ayudaIsOpen():Boolean {
		trace("passo da questa funzione");
		return ayudaOpen;
	}
	public function callMe():Void {
		dispatchEvent({type:"hearing", target:this});
	}
	public function closemcMenu(myx:Number, myy:Number, myButtonX:Number, 
myMenu:MovieClip, myButton:MovieClip):Void {
		myMenu.slideTo(myx, myy, 0.5, "easeInOutCircular");
		myButton._x = myButtonX;
		ayudaOpen = false;
	}
	public function openmcMenu(myx:Number, myy:Number, myButtonX:Number, 
myMenu:MovieClip, myButton:MovieClip):Void {
		myMenu.slideTo(myx, myy, 0.5, "easeInOutCircular");
		myButton._x = myButtonX;
		ayudaOpen = true;
	}
	public function menuDispatcher(butName:String){
		var eventObject:Object = {target:this, type:'pressed'};
		eventObject.buttonPressed = butName;
//eventObject.whereDrawn = cliptoDrawin.square_mc;
	 dispatchEvent(eventObject);
	}
}
--------------
code in the first frame

var my_xml:XML = new XML();
var myEngine:courseEngine = new courseEngine();
var oViewListener:Object = new Object();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success) {
	myEngine.initMenu(mcMenuContainer, my_xml);
};
my_xml.load("Menu.xml");

oViewListener.pressed = function(oEvent:Object):Void  {
	trace(oEvent.type);
	trace(oEvent.buttonPressed);
};

myEngine.addEventListener("pressed", oViewListener);
--------------
and this is the code in the first frame of the movieclip that works as a 
building block of the menu

this.useHandCursor = true;
var oResetColor:Object = {ra:100, rb:0, ga:100, gb:0, ba:100, bb:0, 
aa:100, ab:0};
var oPressColor:Object = {ra:100, rb:100, ga:100, gb:100, ba:100, 
bb:100, aa:100, ab:100};
var oOverColor:Object = {ra:100, rb:0, ga:100, gb:50, ba:50, bb:50, 
aa:100, ab:50};
var mcGboxColor:Object = new Color(mcGreenBox);
var myMovieDelegate:String = new String();
var selectedButton:Boolean = new Boolean();


function setMovieDelegate(stringSomething:String) {
	myMovieDelegate = stringSomething;
}

onRollOver = function () {
	mcGboxColor.setTransform(oOverColor);
};
onRollOut = function () {
	if (selectedButton == true) {
	} else {
		mcGboxColor.setTransform(oResetColor);
	}
};
onPress = function () {
	_root.myEngine.menuDispatcher(this);
	mcGboxColor.setTransform(oPressColor);
};
onRelease = function () {
	mcGboxColor.setTransform(oOverColor);
};
onReleaseOutside = function () {
	if (selectedButton) {
	} else {
		mcGboxColor.setTransform(oResetColor);
	}
};

maybe now is easier to find the problem.

3.accessing a variable in a movieclip from external class

blemmo wrote:
> Hm, I setup a Flash movie like that, and have the same problem. It seems that 
> all the variables and functions of the duplicated Movieclip are lost (also if 
> you attach that MC). Besides that, when I want to list all variables in debug 
> mode, Flash crashes. :(
> 
>  Anyway, it seems to work if you set the variable in the MC directly:
>  drawInIt.myMovieDelegate = pippo;

the problem is that I need to set the variable with something that's in 
the XML file.

4.accessing a variable in a movieclip from external class

blemmo wrote:
> Hi,
> 
>  I can't see a scope problem here, assuming 'mybutton' and 'my_xml' are on the 
> same level/frame.
>  If you use
>  var myMovieDelegate:String = new String();
>  then you have to assign the value like that:
>  mybutton.myMovieDelegate = my_xml.childNodes.childNodes.attributes.MovieToLoad;
> 
>  Your second idea should work, if you call it correctly with
>  mybutton.setMovieDelegate(my_xml.childNodes.childNodes.attributes.MovieToLoad);

the problem is, it doesn't works... why? if you need it, I can post all 
the code of the class and what's in the movie.

5.AS2.0 linking external class with MovieClip, cannot refer to movieclips instances and variables

Im trying to create a movieclip with a linked external class that 
extends the MovieClip class. It sort of works but I cant refer to the 
movieclips instances and variables.

First I made a movieclip with 2 textField instances with I called 
"title" and "description".
then i marked the clip av linked and typed the classname "Module_tv" as 
the AS2.0 classname.

the external classfile looks lite this:

class Module_tv extends MovieClip
{
	function Module_tv(){
		title.text = "The title";
		description.text = "The description";
	}
}

the output windows shows:
**Error** D:\Work\Sajt\Classes\Module_tv.as: Line 5: There is no 
property with the name 'title'.
      		title.text = "The title";

**Error** D:\Work\Sajt\Classes\Module_tv.as: Line 6: There is no 
property with the name 'description'.
      		description.text = "The description";

Total ActionScript Errors: 2 	 Reported Errors: 2


if I replace the code with this it shows that it is run.

class Module_tv extends MovieClip
{
	function Module_tv(){
		trace("Yep it is run allrigth!");
	}
}


Does anyone have a solution to the problem?
/Christoffer

6. AS2.0 linking external class with MovieClip, cannot refer to movieclips instances and variables

7. calling setTimeout within custom class and cannot access the class' variables

8. problem accessing movieclip contents from linked AS 2.0 class



Return to FLASH

 

Who is online

Users browsing this forum: No registered users and 62 guest