PDA

View Full Version : A very strange occurence.



funkmasterta
October 7th, 2009, 12:51 AM
I've never encountered this before and I'm having a bloody time trying to figure out what's wrong!

I have 2 classes. This is the first class:


package
{
import flash.display.MovieClip;

public class myClass1 extends MovieClip
{
private var sTest:String;
private var myMC:MovieClip;

public function myClass1()
{
super();
sTest = "inside";
trace("Traced from private function: " + sTest);
myMC.width = 200;
}

public function change():void {
sTest = "outside";
trace("Traced from public function: " + sTest);
myMC.width = 10;
}
}
}

This is the second class:


package
{
import flash.display.MovieClip;
import myClass1;

public class myClass2 extends MovieClip
{
private var mc1:myClass1;

public function myClass2()
{
super();
mc1 = new myClass1();
mc1.change();
}
}
}

When I compile, I get this in the output panel:



Traced from private function: inside
Traced from public function: inside


And the myMC movie is still 200 wide?

Any ideas why the public function isn't assigning values to the variable and not able to change the property of the movieclip?

This is the strangest bug I've ever seen. Any ideas would be great! :pac:

lewi-p
October 7th, 2009, 04:44 AM
Try delcaring 'sTest' at the top of your class with all the other variables;


private var sTest:String;
private var myString:String;
private var myMC:MovieClip;
lewi-p

IQAndreas
October 7th, 2009, 06:35 AM
I don't see anywhere where you are creating a new instance of "myMC", so there is more to your code that you are not including.

Do you have any code inside of myMC that might be preventing this change?
Try changing the scaleX property instead and see if it makes a difference.

funkmasterta
October 7th, 2009, 10:11 AM
Try delcaring 'sTest' at the top of your class with all the other variables;


ActionScript Code:

private var sTest:String;</p>
<p>private var myString:String;</p>
<p>private var myMC:MovieClip;



lewi-p

Ooops, my bad, it was actually already declared but it was late and I wrote it in here wrong.

The main issue is that I can't assign variables or manipulate the properties of a MC in a public function that is called outside that class.