I'm trying to access a function I've defined in an .as file I've imported. However, I keep getting error 1084. Can somebody please tell me what I'm doing wrong?
Here is the code from my .fla file:
import .com.script.Script.as.*;
var a = new draggable();
Here is the code from my .as file:
package com.script{
import flash.display.Sprite;
import flash.events.*;
public class Script {
public var value:Number;
private var max:Number;
private var min:Number;
function draggable() {
min=bar_mc.y;
max=bar_mc.height-Erhu_H3_btn.height;
toErhu_H3_btn.addEventListener(MouseEvent.MOUSE_DOWN, dragHandle);
}
}
}
Try this code.
your .fla file
import com.script.Draggable;
var a = new Draggable();
Here is the code from your .as file:
package com.script{
import flash.display.*;
import flash.events.*;
public class Draggable{
public var value:Number;
private var max:Number;
private var min:Number;
public function Draggable(){
min=bar_mc.y;
max=bar_mc.height-Erhu_H3_btn.height;
toErhu_H3_btn.addEventListener(MouseEvent.MOUSE_DOWN, dragHandle);
}
}
}
Related
I am trying to import my original package.
But it is said that there is no class files form Akirasda1972_001.as.
My package file is uploaded on sexydesign.club/particle/.
package{
import flash.display.Sprite;
import club.sexydesign.particle.Akirasada1972_001;
public class akirasada1972_002 extends Sprite{
private var akirasada1972_001:Akirasada1972_001;
public function akirasada1972_002():void{
akirasada1972_001=new Akirasada1972_001();
akirasada1972_001.Akirasada1972_001();
addChild(akirasada1972_001);
}
}
}
I've only recently started using as so sorry for this
as its probably pretty simple. Im basically trying to spawn an AI unit but am getting the error 1009, here is the full error.
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at code::Init()[D:\FlashGame\code\Init.as:21]
Im trying to use a function from another class which is in another file. Here is the first file.
package code
{
import flash.display.DisplayObjectContainer;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.KeyboardEvent;
import flash.ui.Keyboard;
import flash.events.MouseEvent;
import flash.text.TextField;
import code.functions.AIManager;
public class Init extends MovieClip
{
private var _AI:AIManager;
private var _player:MovieClip;
public function Init()
{
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
_AI.createAI();
}
public function enterFrameHandler(event:Event):void
{}
}
}
And the second file..
package code.functions
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.DisplayObjectContainer;
public class AIManager extends MovieClip
{
private var _ai:MovieClip;
public function AIManager()
{
createAI();
stage.addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
public function createAI():void
{
_ai = new AI();
_ai.x = stage.stageWidth / 2;
_ai.y = stage.stageHeight / 2;
stage.addChild(_ai);
}
You need to create an instance of a class before you can use it's methods. The exception to that is static methods. In your case you just need to use new AIManager
_AI = new AIManager();
_AI.createAI();
I'm trying to link my .as file to my Flash program. Below is the code from my .as file:
package com.project {
import flash.display.Sprite;
import flash.events.*;
public class Program extends Sprite{
public var value:Number;
private var max:Number;
private var min:Number;
function draggable()
{
min = bar_mc.y;
max = bar_mc.height - Erhu_H3_btn.height;
Erhu_H3_btn.addEventListener(MouseEvent.MOUSE_DOWN, dragHandle);
}
function dragHandle(event:MouseEvent):void
{
Erhu_H3_btn.startDrag(false, new Rectangle(0,min,0,max));
stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
}
function stopDragging(event:MouseEvent):void
{
Erhu_H3_btn.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, stopDragging);
}
}
}
Below is the code in my Flash file:
import com.script.Script;
stop();
var Program:Program = new Program();
Can someone please tell me what I'm doing wrong? I keep getting error 1046! Thanks! :)
You probably missed importing statement
import com.project.Program
package{
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
public class Main extends MovieClip{
public var ability1,ability3:Ability;
public function Main(){
var ability1 = new Ability(30,30,"Ability Name","...",5,false);
addChild(ability1);
var ability2 = new Ability(60,30,"Ability Name2","...",3,false);
addChild(ability2);
var ability3 = new Ability(45,60,"Ability Name3","...",5,true);
addChild(ability3);
stage.addEventListener(MouseEvent.CLICK, Check);
trace(ability1.Points); //outputs the value
}
public function Check(event:MouseEvent):void{
trace(ability1.Points); //outputs error
}
}}
Second trace gives this error:"TypeError: Error #1010: A term is undefined and has no properties. at Main/Check()" Can you point me out at least?
Thanks.
By using the var statement in your Main method, you're assigning the instances to local variables which are only scoped within that method. Update your code as follows and you should get the results you expect:
package{
import flash.display.MovieClip;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
public class Main extends MovieClip{
public var ability1:Ability;
public var ability3:Ability;
public function Main(){
// I'm a local property scoped only to this method
var ability2 = new Ability(60,30,"Ability Name2","...",3,false);
addChild(ability2);
// We're instance properties and can be accessed from any method
// in the class (and from outside the class as well)
ability1 = new Ability(30,30,"Ability Name","...",5,false);
addChild(ability1);
ability3 = new Ability(45,60,"Ability Name3","...",5,true);
addChild(ability3);
stage.addEventListener(MouseEvent.CLICK, Check);
trace(ability1.Points); //outputs the value
}
public function Check(event:MouseEvent):void{
trace(ability1.Points); //outputs the value
trace(ability3.Points); //outputs the other value
}
}
}
I try to make a connection between arduino and Flex 4.0, I added the JSON lib and also as3corelib.swc to Flex. When I run the Flex file the connection between PC to arduino is working (I can see it in SERPROXY window) and also I don't have any problems in Flex window, I added the SWF file of Flex to the list at //http://www.macromedia.com/support/documentation/tr/flashplayer/help/settings_manager04.html, Bu the reading result is not shows in the SWF, I couldn't understand why !, thanks for help
and here the code
package
{
import com.adobe.serialization.json.JSON;
//http://www.macromedia.com/support/documentation/tr/flashplayer/help/settings_manager04.html
import flash.display.Sprite;
import flash.errors.*;
import flash.events.*;
import flash.net.Socket;
import flash.text.TextField;
public class deneme extends Sprite
{
private var magnetic:Socket=new Socket("localhost",5331);
private var magneticValue:Number=0;
private var distance:Number;
private var newText:TextField=new TextField();
private var listText:TextField=new TextField();
private var MNx:Number;
private var MNy:Number;
private var MNz:Number;
private var d:Object={"x":null, "y":null, "z":null};
public function deneme()
{
socketDataHandler();
}
private function socketDataHandler():void
{
newText.text=magnetic.readUTFBytes(magnetic.bytesAvailable);
d= JSON.decode(newText.text);
MNx=d["x"];
MNy=d["y"];
MNz=d["z"];
listText.x=10;
listText.y=10;
listText.width=600;
listText.height=100;
listText.text=newText.text;
addChild(newText);
}
}
}
package
{ import com.adobe.serialization.json.JSON;
import flash.display.Sprite;
import flash.errors.*;
import flash.events.*;
import flash.net.Socket;
import flash.text.TextField;
import mx.rpc.events.ResultEvent;
public class deneme2 extends Sprite
{
private var newText:TextField=new TextField();
private var listText:TextField=new TextField();
private var magnetic:Socket=new Socket("localhost",5331);
private var MNx:Number;
private var MNy:Number;
private var MNz:Number;
private var d:Object={"x":null, "y":null, "z":null};
public function deneme2()
{
magnetic.addEventListener(ProgressEvent.SOCKET_DATA,getDATA);
}
private function getDATA(event:ProgressEvent):void
{
newText.text=magnetic.readUTFBytes(magnetic.bytesAvailable);
d= JSON.decode(newText.text);
MNx=d["x"];
MNy=d["y"];
MNz=d["z"];
listText.x=10;
listText.y=10;
listText.width=600;
listText.height=100;
listText.text="X="+String(MNx)+" Y="+String(MNy)+" Z="+String(MNz);
addChild(listText);
}
}
}