package com.powerflasher.SampleApp {
import flash.events.MouseEvent;
import flash.display.Sprite;
public class test1 extends Sprite {
public function test1()
{
NewCircle1();
NewButton1();
Magic();
}
private function NewButton1():void
{
var NewButton:Sprite = new Sprite();
NewButton.graphics.beginFill(0x0000ff,1);
NewButton.graphics.drawRect(100, 100, 50, 50);
NewButton.graphics.endFill();
addChild(NewButton);
NewButton.addEventListener(MouseEvent.CLICK, Magic);
}
private function NewCircle1():void
{
var NewCircle:Sprite = new Sprite();
NewCircle.graphics.beginFill(0x000000,1);
NewCircle.graphics.drawCircle(400, 500, 50);
NewCircle.graphics.endFill();
addChild(NewCircle);
}
private function Magic():void {
Tweenlite.to(NewCircle1(), 2+Math.random()*6, {x:Math.random()*20, y:Math.random()*25, scaleX:Math.random()*3, ScaleY:Math.random()*5});
}}}
All that i'm trying to do is to draw square, draw circle, and on mouse click on square to move circle to random location
getting error "Variable 'Tweenlite' is not declared", have no idea..
There are several issues with your code, but in regards to your initial question, you need to import Tweenlite if you want to use it in your class.
import com.greensock.Tweenlite;
But you also have other problems with your code that will likely cause a problem next. You are using local variables to store your sprite instances. That means the variable name will not persist beyond the completion of those methods.
NewButton and NewCircle need to be made class properties so that they are available to the all the methods in the class.
Here's an example :
package com.powerflasher.SampleApp {
import flash.events.MouseEvent;
import flash.display.Sprite;
import com.greensock.Tweenlite; // import Tweenlite
public class test1 extends Sprite {
// declare your class properties
public var NewButton:Sprite;
public var NewCircle:Sprite;
public function test1()
{
NewCircle1();
NewButton1();
Magic();
}
private function NewButton1():void
{
NewButton = new Sprite();
NewButton.graphics.beginFill(0x0000ff,1);
NewButton.graphics.drawRect(100, 100, 50, 50);
NewButton.graphics.endFill();
addChild(NewButton);
NewButton.addEventListener(MouseEvent.CLICK, Magic);
}
private function NewCircle1():void
{
NewCircle = new Sprite();
NewCircle.graphics.beginFill(0x000000,1);
NewCircle.graphics.drawCircle(400, 500, 50);
NewCircle.graphics.endFill();
addChild(NewCircle);
}
private function Magic():void
{
Tweenlite.to(NewCircle, 2+Math.random()*6, {x:Math.random()*20, y:Math.random()*25, scaleX:Math.random()*3, ScaleY:Math.random()*5});
}
}
}