Importing Class To Custom Class
I'm writing my own class. (The Peacock class if you want to know.) I want to use the Tween class in my class, but I don't know how to import another class into my class. How do I go about that. Thanks.
Adobe > ActionScript 1 and 2
Posted on: 01/21/2007 07:28:04 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Importing Class Into Custom Class
Hi there, I realise I'm not allowed to import classes into other classes but I am not sure how to achieve what I want. I want 2 custom classes to pass data one from another directly. I have 2 custom classes I want to use: one extends the XMLSocket Class:
ActionScript Code:
class Game extends XMLSocket { import XMLParser //not allowed to do this I know! var parser:XMLParser = new XMLParser(); function onXML(src:XML):Void { //trace("xml:"+src); parser.parseIt(src); }}
....and the other is a custom class I want to use to parse XML data that the Game class receives from its XML Socket:
ActionScript Code:
class XMLParser { public function XMLParser() { // constructor } function parseIt(theXML:XML):Void { trace("xmlParser received:"+theXML.toString()); //parsing code goes here }}
As I say I realise I am not allowed to import the parsing class into my Game class (or any class for that matter) but I don't know how to pass data directly between these two classes without referencing them in the main FLA.
If anyone could let me know that would be a massive help, thanks !
Schm
Problem Importing A Custom Class
This is the problem.
I made a custom class, (without error). I saved it in a folder that is in the same path than the my swf. I want to import the class into on of these movies and this error appears:
The class 'clases.test' could not be loaded.
var file:test = new test();
clases is the folder.
test is the class, I also tried importing with *, but the same error appears. Please I need some help. THANKS
Calling SetTimeout Within Custom Class And Cannot Access The Class' Variables
Hi All,
I'm creating an user interface with Flash 8, I'm new to Flash, my background is Java therefore I decided to use ActionScript to create a custom component that is reference within an external file.
My problem I believe is scope related. I have a status bar (label component), once I update the status bar I want to call the
"setTimeout" function to wait a couple of seconds before clearing my status bar. The "setTimeout" function is executing, but for some reason my status bar is not being cleared (accessed).
Below is a snippet of my code. Any help appreciated. Thanks.
/*
External File
*/
import mx.controls.Button;
import mx.controls.Label;
class MyApp
{
//private properties
private var mc_container:MovieClip;
private var btn:Button;
private var lbl_status:Label;
private var str:String = "do see me";
//constructor
public function MyApp(target:MovieClip)
{
trace("-- MyApp --");
mc_container = target.createEmptyMovieClip("mc_container", 100);
}
//public methods
public function init(width:Number, height: Number, xPos:Number, yPos:Number):Void
{
var my_app:MyApp = this;
btn = mc_container.createClassObject(Button, "btn", 1, {label:"click me"});
btn.setSize(100, 25);
btn.move(10, 10);
btn.clickHandler = function():Void
{
trace("btn clicked");
setTimeout(my_app.clearStatus, 2400);
//correct if I call directly
//my_app.clearStatus();
trace(str);
}
lbl_status = mc_container.createClassObject(Label, "lbl_status", 2, {text:"status bar message"});
lbl_status.setSize(200, 25);
lbl_status.move(0, 50);
}
public function clearStatus():Void
{
trace("calling clearStatus");
lbl_status.text = "";
}
}
/*
Called for Flash IDE
*/
var app:MyApp = new MyApp(this);
app.init(200, 200, 0, 0);
[AS3] Making An Auto-generated Class Inherit From Custom Class?
hi, just wondering if this is possible
i was hoping to find a way to get a bunch of objects in my library to inherit from (or even be) one class that i have made, but without having to make .as files for every single one
is this possible, or is there any other way to give objects another classes functionality in an auto-generated class?
cheers
[F8] Problem With Using A Custom Class Inside A Custom Class
I'm getting this error:
Line 19: A function call on a non-function was attempted.
var a:Meter = new Meter(32,34,0x0000ff,0,0);
when I am trying to call a custom class (Meter) inside of another custom class, which I initialize in the main timeline. I can do this exact same line I copied above in the main timeline and it will work just fine, but not if it is used in the constructor of another custom class as I am trying to do. Any ideas on why this isn't working? Only thing I can come up with is that the class isn't imported at the time of the second class calling it but I've tried fixing that already.
Tween Class Applied In Custom Class Not Working
var sizerW:Object = new Tween(pda_mc,"_xscale",mx.transitions.Tween.None.e aseNone,pdaOrigW,pdaSmallW,3,true);
this code produces and error when applied in a custom class but not in a fla?
the error = There is no property with the name 'None'.
Custom Transitionmanager Class Problem/class Scope?
I'm writing a class that fades from one scene to another in a video game. A custom transitionManager object is created, and a listener is attached. Once the fade out from one scene is complete, the listener is triggered, the scene switches, and the new scene fades in.
This is the error I'm getting: "There is no method with the name 'myTransitionManager'.
myTransitionManager.addEventListener("allTransitio nsOutDone", fadeListener);". It is given everytime myTransitionManager is accessed by any of the class functions.
I assume this is a class scope issue. How can I create a custom transitionManager object accessable to the entire class? I need it to be accessed by at least three separate class functions.
Here's the source, starting with the constructor for the GameSection class:
Code:
public function GameSection(clip_to_fade:MovieClip){
var myTransitionManager:TransitionManager = new TransitionManager();
}
//class methods
function switch_section(clip_to_fade:MovieClip, fade_in_scene:String) {
// Define a listener object to use with the Tween objects.
var fadeListener:Object = new Object();
//create event listener for transitions being complete
fadeListener.allTransitionsOutDone = function(eventObj:Object) {
trace("allTransitionsOutDone event occurred.");
gotoAndPlay(fade_in_scene);
fadeIn(clip_to_fade);
};
myTransitionManager.addEventListener("allTransitionsOutDone", fadeListener);
fadeOut(clip_to_fade);
}
function fadeIn(in_mc:MovieClip) {
myTransitionManager.start(in_mc, {type:Fade, direction:Transition.IN, duration:1, easing:None.easeNone});
}
function fadeOut(out_mc:MovieClip) {
myTransitionManager.start(out_mc, {type:Fade, direction:Transition.OUT, duration:1, easing:None.easeNone});
}
Thanks!
How Do You Listen In One Class For A Custom Event Dispatched From Another Class?
I am not sure how to word this, so here is what I would like to happen:
MyDocumentClass contains an instance of MyItem and MyItemManager. MyItem will fire an ItemEvent.ITEM_CHANGED event. I want MyItemManager to listen and react to that event. Possible? Here's my code:
ItemEvent.as:
ActionScript Code:
package
{
import flash.events.Event;
public class ItemEvent extends Event
{
public static const ITEM_EVENT:String = "itemEvent";
public function ItemEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false)
{
super(type, true);
}
public override function clone():Event
{
return new ItemEvent(type);
}
public override function toString():String
{
return formatToString("ItemEvent", "type", "bubbles", "cancelable");
}
}
}
MyDocumentClass.as:
ActionScript Code:
package {
import flash.display.Sprite;
import MyItem;
import MyItemManager;
public class MyDocumentClass extends Sprite
{
public var item:MyItem;
public var manager:MyItemManager;
public function MyDocumentClass()
{
item = new MyItem();
manager = new MyItemManager();
item.dispatchCustomEvent();
}
}
}
MyItem.as:
ActionScript Code:
package
{
import flash.display.Sprite;
import flash.events.EventDispatcher;
import ItemEvent;
public class MyItem extends Sprite
{
public function MyItem()
{
}
public function dispatchCustomEvent():void
{
dispatchEvent(new ItemEvent(ItemEvent.ITEM_EVENT));
}
}
}
MyItemManager.as:
ActionScript Code:
package
{
import flash.display.Sprite;
import ItemEvent;
import flash.events.EventDispatcher;
public class MyItemManager extends Sprite
{
public function MyItemManager()
{
addEventListener(ItemEvent.ITEM_EVENT, handleItemEvent);
}
public function handleItemEvent(e:ItemEvent):void
{
// do something here
}
}
}
Applying A Custom Class To An Object In The Document Class...
How's it going guys. I just started learning Actionscript 3.0 and so far not bad. However, I'm having trouble applying custom created classes to objects in the main document class. I'm using Flash as the application, however there is no timeline scripting involved. I loaded the document class called Main.as:
ActionScript Code:
package
{
import flash.display.MovieClip;
import flash.net.URLRequest;
import flash.display.Loader;
public class Main extends MovieClip
{
private var _redBox:Loader = new Loader();
private var _redBoxLink:URLRequest = new URLRequest("images/redbox.jpg");
public var buttonScaleHover:ButtonScaleHover = new ButtonScaleHover();
public function Main()
{
_redBox.x = 100;
_redBox.y = 100;
_redBox.load(_redBoxLink);
addChild(_redBox);
}
}
}
Now, what I'm trying to do is apply this class named ButtonScaleHover.as to the _redBox in the document class. Here is the code for ButtonScaleHover:
ActionScript Code:
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class ButtonScaleHover extends Sprite
{
private var _xScale:Number;
private var _yScale:Number;
public function ButtonScaleHover()
{
trace("The ButtonScaleHover Class is being loaded");
_xScale = this.scaleX
_yScale = this.scaleY
this.addEventListener(MouseEvent.ROLL_OVER, onRollOver);
this.addEventListener(MouseEvent.ROLL_OUT, onRollOut);
}
public function onRollOver(event:MouseEvent):void
{
this.scaleX *= 2;
this.scaleY *= 2;
}
private function onRollOut(event:MouseEvent):void
{
this.scaleX = _xScale;
this.scaleY = _yScale;
}
}
}
I tried using
ActionScript Code:
_redBox.ButtonScaleHover();
in the document class after i added it to the display object list. However, it didn't work. Basically, I'm just trying to apply a custom class to an object(in this case the loader). Thank you guys very much in advance.
Tween Class In Custom Extend MovieClip Class
I want to use the tween prototype in a custom class that extends MovieClip. I am already including "lmc_tween.as" in my root and I have already replaced the "MovieClip.as" file in my flash directory with the one from the shared/Zigo directory. However, I still get compiler errors if I try to include "lmc_tween.as" in the class file, or without the include in the class it will compile but the tween prototype will not work in the custom class. Does anyone know how to fix this?
Applying A Custom Class To An Object In The Document Class...
How's it going guys. I just started learning Actionscript 3.0 and so far not bad. However, I'm having trouble applying custom created classes to objects in the main document class. I'm using Flash as the application, however there is no timeline scripting involved. I loaded the document class called Main.as:
package
{
import flash.display.MovieClip;
import flash.net.URLRequest;
import flash.display.Loader;
public class Main extends MovieClip
{
private var _redBox:Loader = new Loader();
private var _redBoxLink:URLRequest = new URLRequest("images/redbox.jpg");
public var buttonScaleHover:ButtonScaleHover = new ButtonScaleHover();
public function Main()
{
_redBox.x = 100;
_redBox.y = 100;
_redBox.load(_redBoxLink);
addChild(_redBox);
}
}
}
Now, what I'm trying to do is apply this class named ButtonScaleHover.as to the _redBox in the document class. Here is the code for ButtonScaleHover:
package
{
import flash.display.Sprite;
import flash.events.MouseEvent;
public class ButtonScaleHover extends Sprite
{
private var _xScale:Number;
private var _yScale:Number;
public function ButtonScaleHover()
{
trace("The ButtonScaleHover Class is being loaded");
_xScale = this.scaleX
_yScale = this.scaleY
this.addEventListener(MouseEvent.ROLL_OVER, onRollOver);
this.addEventListener(MouseEvent.ROLL_OUT, onRollOut);
}
public function onRollOver(event:MouseEvent):void
{
this.scaleX *= 2;
this.scaleY *= 2;
}
private function onRollOut(event:MouseEvent):void
{
this.scaleX = _xScale;
this.scaleY = _yScale;
}
}
}
I tried using
_redBox.ButtonScaleHover();in the document class after i added it to the display object list. However, it didn't work. Basically, I'm just trying to apply a custom class to an object(in this case the loader). Thank you guys very much in advance.
Doc Class Talks To Custom Class Problems
Hello all,
I am trying to get a Doc class to initiate a function in custom class, but I cant get it to work. I am still very new to working with classes and hope any of you can shine some light onto this problem.
I have 2 MovieClips, one is animating across the the stage via its custom class, and the other is a button control through the Doc class. I want to button to stop the stage.event from animating the first movie across the stage and to rotate the movieclip a value of 20.
So far the movie clip just keeps on going and does not stop.
Here is my Doc Class Code.
Code:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import mcSquare;
import Movesq;
public class MasterMain extends MovieClip
{
private var _square:Movesq;
public function MasterMain ()
{
_square = new mcSquare;
btn.addEventListener(MouseEvent.CLICK, stopBlackSquare, false, 0, true);
btn.buttonMode = true;
}
private function stopBlackSquare():void
{
_square.stopLoop();
}
}
}
Here is the Custom class code ( class name is Movesq)
Code:
package
{
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.*;
public class Movesq extends MovieClip
{
public function Movesq ()
{
this.addEventListener (Event.ENTER_FRAME, onLoop, false, 0, true);
}
private function onLoop (evt:Event):void
{
this.x +=5;
}
public function stopLoop ():void
{
this.rotation = 20;
this.removeEventListener (Event.ENTER_FRAME, onLoop);
}
}
thank you for your help in advance.
Pending Class OnResult In Custom Class.
Ok,
I have a custom class with private field:
private var test:Stringint the constructor I load the web service:
pws = new WebService(Constants.getWsURL() + "?WSDL");
then I call a method on the WS:
var pcLoadModel = pws.LoadModel();
pcLoadModel.onResult = pcLoadModel_Succ;
pcLoadModel.onFault = pcLoadModel_Fail;
where:
public function pcLoadModel_Succ(result){
//some code.
}
The problem is that where it says "some code", I cant access the members of my class! Why not? in the debugger I clearly see that I have left the scope of the instance of the class I was working from. I dont understand why this happens.
Anyone has an answer to this?
Thanks you :)
Jp
Dynamic Class Reference In Custom Class
I've created a custom class that I want to be able to dynamically insert a movie clip from the library. I'm running into trouble because I want to access the clip as a property of the custom class object (ie: so it can be swapped out for another library clip after instantiation, among other things). I'm using getDefinitionByName() but I can't use it outside my addDiagram() function (see attached code) because the string variable that stores the name of the library clip isn't defined until after the custom class constructor function. Any help is appreciated!
Thanks,
-Erik
Attach Code
public function Panel(panelTitle:String,
panelWidth:Number,
panelHeight:Number,
panelX:Number,
panelY:Number,
panelType:String = "",
panelDisplay:String = ""):void {
this.panelTitle = panelTitle;
this.panelWidth = panelWidth;
this.panelHeight = panelHeight;
this.panelX = panelX;
this.panelY = panelY;
this.panelType = panelType;
this.panelDisplay = panelDisplay;
...
//if panel is to display a diagram, add the diagram clip
protected function addDiagram():void {
var diagramClass:Class = getDefinitionByName(panelDisplay) as Class;
var panelDiagram:* = new diagramClass();
panelDiagram.x = getPanelX() + 5;
panelDiagram.y = getPanelY() + 20;
panelDiagram.scaleX = .95;
panelDiagram.scaleY = .65;
addChild(panelDiagram);
}
A Custom Class Says My Class Is Null
Hi,
I have a class (Math2) with misc functions for my project. It has a function called CheckRelations() which basically checks a static array in another class (relation). But the Math2 class acts as if the Relation class is non-existent, even though I have imported it and I also have all files in the same folder. When I try to relate to the class in any way i get a Runtime-Error 1009 (Cannot access a property or method of a null object reference.)
I tried tracing the class along with two other classes (one imported, but another is not) the two classes trace fine: [class Human] [class relationship]. The Relation class when traced in the Math2 class results in a 'null'
Code for the CheckRelations function in math2 class: (takes in String value, and returns the index at which the input = relation.Type ( i.e. if (String_Input == Relation.Relations.Type) --> return i ) Return -1 if not found)
------------------------------------------------------------------------------------------------------------------------------
import Human;
import Relation; //notice that Relationship is not imported yet traces out fine
//......REST OF CLASS (other static functions
public static function CheckRelations(relationType:String):int {
///////Variables
trace(Human,Relation,Relationship); //Human and Relationship are classes I used to test problem
//Output: [class Human] null [class Relationship]
var relationType:String;
//relationType: the relation to look for in the relations array
var array:Array = Relation.Relations; //Relations is a public static var (array)
//array: the array to look inside
var relation:Relation;
//relation: used to hold temp values of relations to compare
var ReturnValue:int = -1;
//ReturnValue: the value to return
var i:uint;
//i: used in for..loops
///////Function
//SOURCE OF ERROR: any reference to Relation class
RelationCheck:for (i = 0; i < array.length; i++) {
relation = array as Relation;
if (relation.Type == relationType) { //relation.Type is a string value
ReturnValue = i;
break RelationCheck;
}
}
return ReturnValue;
}
------------------------------------------------------------------------------------------------------------------------------
Code for getRelation function in Relation class:
----------------------------------------------------------------------------------------------------------------------------
public static function getRelation(relation:String):Relation {
var val:int = Math2.CheckRelations(relation); // SOURCE OF ERROR
if (val == -1) {
GameError.InvalidRelation(relation); //throws error when an invalid relation is specified {this is NOT the problem I'm having}
}return Relations[relation];
}
---------------------------------------------------------------------------------------------------------------------------------------------------
Importing Class Help...
I am trying to import a class I downloaded from http://www.devpro.it/as2_id_44.html to MD5 encrypt passwords for a login check.
I can't seem to import it correctly. I have two files: md5.fla and Class.md5.as, both of which reside in the same folder.
My code attempt to get this working looks like:
Code:
import Class.md5;
var m:md5 = new md5();
trace( m.hash( "my string" ) );
But I get this error: "The class or interface 'Class.md5' could not be loaded."
Any help would be appreciated!
Importing Class
I was reading the tutorial on importing class's. This is what I read
Importing classes
To reference a class in another script, you must prefix the class name with the class's package path. The combination of a class's name and its package path is the class's fully qualified class name. If a class resides in a top-level classpath directory--not in a subdirectory in the classpath directory--then its fully qualified class name is its class name.
To specify package paths, use dot (.) notation to separate package directory names. Package paths are hierarchical, where each dot represents a nested directory. For example, suppose you create a class named Data that resides in a com/xyzzycorporation/ package in your classpath. To create an instance of that class, you could specify the fully qualified class name, as shown in the following example:
var dataInstance = new com.xyzzycorporation.Data();
My Question is about com/xyzzycorporation/ . would the full class parth be c:/com/xyzzycorporation/ . Why do they never state the drive letter when teaching about directories.
Importing A Class
Hello,
I have a series of classes that I need to import. How do I go about doing so? The is the class I need to import first:
Thanks!
Attach Code
package {
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.display.Sprite;
// This is an example usage of the LobbyAPI
// It has a switch statement that you will need to fill in for your own application,
// so it is also a template.
public class LobbyReceiver extends Sprite {
protected var lobby:LobbyAPI = null;
protected var lobbyAddress:String = "";
protected var lobbyPort:int = 0;
protected var handler:ILobbyHandler = null;
// The address and port for the lobby will come from a Web Service, to be written.
// For testing, you can use hard-coded values, which I'll supply when I give you the server code.
public function LobbyReceiver(lh:ILobbyHandler, lobbyAddr:String, lobbyPt:int) {
lobbyAddress = lobbyAddr;
lobbyPort = lobbyPt;
handler = lh;
}
public function initialize():void {
if (lobby != null) {
if ((lobby.status == ConnectionAPI.ACTIVE) || (lobby.status == ConnectionAPI.CONNECTING)) {
return;
}
}
lobby = new LobbyAPI();
lobby.addMsgHandler(lobbyMsgReceived);
lobby.addDisconnectHandler(lobbyDisconnectReceived);
lobby.connect(lobbyAddress, lobbyPort);
}
public function lobbyMsgReceived(msg:WPMessage):void {
switch(msg.type) {
// This is the first message after the call to connect returns.
case WPMessageType.CONNECTION_OPENED:
lobby.requestGamesList();
handler.connectionOpen();
break;
case WPMessageType.NUM_ACTIVE_PLAYERS:
handler.numActivePlayers(msg.getFld(0), msg.getIntFld(1));
break;
// This has 5 fields for each game -- group them into WPGameData objects
// and pass as an Array
case WPMessageType.GAMES_LIST:
var games:Array = new Array();
var idx:int = 0;
while ((idx + 4) < msg.flds.length) {
var game:WPGameData = new WPGameData(msg.getFld(idx),
msg.getFld(idx+1), msg.getIntFld(idx+2),
msg.getIntFld(idx+3), msg.getIntFld(idx+4));
games.push(game);
idx += 5;
}
handler.gamesList(games);
break;
// This is VITAL to maintaining the connection
case WPMessageType.ACK_REQUEST:
var msg:WPMessage = new WPMessage(WPMessageType.ACK_REPLY);
lobby.send(msg);
// Nothing else needs to be done for this one.
break;
default:
// Leave this in temporarily for debugging
trace("Unhandled message type: " + msg.type);
break;
}
}
public function lobbyDisconnectReceived(reason:String):void {
trace(reason);// FOR DEBUGGIN
// at this point, it is best to clear out the lobby object
lobby.addMsgHandler(null);
lobby.addDisconnectHandler(null);
lobby = null;
// to reconnect, call initialize()
}
}
}
Importing Class
hi!
I get the following errors in importing the classes:
**Error** Scene=Scene 1, layer=layer1, frame=1:Line 1: Syntax error.
import mx.transitions.Tween;
**Error** Scene=Scene 1, layer=layer1, frame=1:Line 2: Syntax error.
import mx.transitions.easing.*;
**Error** Scene=Scene 1, layer=layer1, frame=1:Line 3: Syntax error.
import flash.filters.GlowFilter;
Total ActionScript Errors: 3 Reported Errors: 3
the coding is
import mx.transitions.Tween;
import mx.transitions.easing.*;
import flash.filters.GlowFilter;
i have just started learning flash,i don't know what's the reason for these errors.
XML With Custom Class
I am having some difficulties loading XML from an external class. I would like to place the firstChild into a Dynamic Text Box. In my Flash movie the text box is labeled LevelTitle. This is my code at the moment:
Code:
class SelectTest extends XML {
var Testlist: XML;
var curContainer:XMLNode
function SelectTest() {
var Testlist = new XML;
Testlist.load("TestList.xml");
Testlist.ignoreWhite = true;
Testlist.onLoad = getTest()
}
function getTest() {
trace ("success");
var LevelTitle= Testlist.firstChild
trace (LevelTitle);
}
}
It always traces "sucess" leading me to believe that the xml is loading successfully, but when I try to trace LevelTitle, (or Testlist.firstChild, or Testlist.toString()) I always get undefined. What am I doing wrong?
(AS1) Need Some Help With XML And A Custom Class...
Okay, I know I should be able to figure this out, but it's been bugging me for a while. I've created a program that reads in XML and ends up dumping the contents to a class I've written, and the way I have it now, it works. BUT, I'm doing things in a very sloppy way in that my xml.onLoad function is not properly defined as a method of the class, because I'm stumbling over syntax problems with "this".
So, here's the real question. If I'm creating a method for a class which is going to be used as an xml.onLoad function, how do I refer to the xml tree being passed to the function when "this" always relates to the class itself, rather than the xml tree?
And for those like me who can picture these things better when I can see some code, here's an example:
Code:
some_class = function(xmlLocation) {
var xmlInput = new XML();
xmlInput.onLoad = load_xml;
xmlInput.load(xmlLocation);
};
some_class.prototype.load_xml = function() {
var e = this.firstChild;
// the "this" reference points to the class itself
// DOESN'T WORK
};
load_xml = function() {
var e = this.firstChild;
// the "this" reference points to the xml tree
// WORKS but SLOPPY
};
My thanks in advance to anyone brave enough to tackle this one...
Custom Class Help
I wrote a simple class for linking movie clips to external websites. The constructor takes two arguments -- (mc:MovieClip, url:String).
It would probably be easier to take a quick glance at the code in full:
Code:
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
import flash.net.navigateToURL;
import flash.net.URLRequest;
public class MakeLink extends MovieClip {
private var _mc:MovieClip;
private var _url:String;
public function MakeLink(mc:MovieClip, url:String) {
_mc = mc;
_url = url;
_mc.addEventListener(MouseEvent.ROLL_OVER, showHandCursor);
_mc.addEventListener(MouseEvent.CLICK, addURL);
}
private function showHandCursor(event:MouseEvent):void {
_mc.buttonMode = true;
_mc.useHandCursor = true;
}
private function addURL(event:MouseEvent):void {
var request:URLRequest = new URLRequest(_url);
navigateToURL(request, "_blank");
}
}
}
Code:
import MakeLink;
var myLink:MakeLink = new MakeLink(myMC, "http://www.google.com");
Easy enough, but I'm running into some problems adding this functionality to sprites as well. I thought it would be possible to create an optional argument (mc:MovieClip, sp:Sprite, url:String) ... and then just leave out either mc or sp depending on what I need (,sp, url) or (mc,,url) but that spits errors.
What would be the/a proper way of doing this? Any help is appreciated.
Add Custom Class To CS
Total CS/AS3 noob, I'm trying to install/include a class I wish to use with CS -- Fzip
The Fzip files can be found here: http://codeazur.com.br/lab/
Once downloaded, I have a package of files, none of which provide clear details on how to install this package, however all the .as files are within 2 folders: fzip and utils. Those 2 folders are within a parent folder, deng. which resides within the download package as: fzip/src/deng
HTML documentation is provided that refers to the package deng.fzip and within that package are classes FZip, FZipErrorEvent, FZipEvent, FZipFile, FZipLibrary.
No mention is made in the package as to what the 'public definition' is, but I'm assuming it would be the class name, which is the same as the .as file without the .as
So, I've placed the entire download folder in my project's root folder: myproject/fzip, then I've followed the Help instructions to set a classpath to myproject/fzip/src/deng by using the target tool to browse to and choose that folder. Also on the ActionScript 3 Settings pane, I've set Document class to FZip (I'm not sure if that's right, but there's no instructions in the Help files about this field)
Next, on the first line of Frame1, I write the following:
import exampe.FZip;
I test my movie and get: Definition example:FZip could not be found.
I've also tried the entire path to the .as file (with no classpath via Publish settings):
import fzip.src.deng.fzip.FZip;
(fzip/src/deng/fzip/FZip.as)
Any help or ideas much appreciated.
TIA
Len
Help With Custom Class
Sorry if this is a dumb question but I am unclear on this topic since I haven't yet created any custom classes in actionscript. I have a file called Floater.as inside a folder called tod. I have a flash movie that contains the tod folder. Inside my Floater.as file I have the following code. In my movie I'm trying to create an instance of this class by importing tod.Floater and then creating a new Floater object. But when I try I get two errors for the initializer line "var f:Floater = new Floater("test1", "test2");".
1046: Type was not found or was not a compile-time constant: Floater.
1180: Call to a possibly undefined method Floater.
Code:
package tod{
import flash.display.MovieClip;
class Floater extends flash.display.MovieClip{
private var _title:String;
private var _desc:String;
public function Floater(titleText:String, descText:String){
_title = titleText;
_desc = descText;
trace(_title);
}
}
}
Do I have my structure messed up somehow? If not, what am I doing wrong that flash can't see this class I'm trying to create? Thanks.
Custom XML Class
I have a class that loads some XML and returns a XML List, but I think it's not as efficient as it could be - seems to be too heavy in that I'm including a lot of resources that I don't need.
For instance, to dispatch an event, I found that I had to extend at least a Sprite to avoid errors (even with importing event stuff).
I was wondering if anyone had any ideas on how to better do this?
ActionScript Code:
package _resources._packages._fidoXML {
import flash.display.Sprite;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.net.*;
public class fidoXML extends Sprite {
var myXML:XML;
var xmlLoader:URLLoader = new URLLoader;
var myXML_List:XMLList;
public function fidoXML(xmlLoc:String):void {
xmlLoader.load(new URLRequest(xmlLoc));
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, onError);
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
}
private function onError(event:IOErrorEvent):void {
trace(event.text);
}
private function xmlLoaded(event:Event):void {
myXML = XML(event.target.data);
myXML_List = myXML.children();
dispatchEvent(new Event('xmlLoaded'));
}
public function get fidoXMLList():XMLList {
return myXML_List;
}
}
}
Help With Custom Class
Below is the code I have in my .as file (called "BallGameClass.as"). It doesn't work and I get these errors in the output panel:
_____
1120: Access of undefined property stage.
1120: Access of undefined property moveMC.
1120: Access of undefined property keyPressed.
1120: Access of undefined property keyReleased.
1120: Access of undefined property rotateMC.
_____
Any help is appreciated. Thanks in advance.
ActionScript Code:
package
{
import flash.display.MovieClip;
import flash.events.*;
class BallGameClass extends MovieClip
{
var yspeed:Number = 0;
var xspeed:Number = 0;
var wind:Number = 0.00;
var power:Number = 0.65;
var gravity:Number = 0.1;
var upconstant:Number = 0.75;
var friction:Number = 0.99;
var upKeyDown:Boolean = false;
var downKeyDown:Boolean = false;
var leftKeyDown:Boolean = false;
var rightKeyDown:Boolean = false;
stage.addEventListener(Event.ENTER_FRAME, moveMC);
function moveMC(event:Event):void {
this.y = this.y + yspeed;
this.x = this.x + xspeed;
xspeed = (xspeed + wind) * friction;
yspeed = yspeed + gravity;
if (upKeyDown == true) {
yspeed = yspeed - power * upconstant;
}
if (downKeyDown == true) {
yspeed = yspeed + power * upconstant;
}
if (leftKeyDown == true) {
xspeed = xspeed - power;
}
if (rightKeyDown == true) {
xspeed = xspeed + power;
}
}
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
function keyPressed(event:KeyboardEvent):void
{
if (event.keyCode == 38){
upKeyDown = true;
}
if (event.keyCode == 37){
leftKeyDown = true;
}
if (event.keyCode == 39){
rightKeyDown = true;
}
if (event.keyCode == 40){
downKeyDown = true;
}
}
function keyReleased(event:KeyboardEvent):void
{
if (event.keyCode == 38){
upKeyDown = false;
}
if (event.keyCode == 37){
leftKeyDown = false;
}
if (event.keyCode == 39){
rightKeyDown = false;
}
if (event.keyCode == 40){
downKeyDown = false;
}
}
function convert(radians:Number):Number {
var degrees = radians * (180 / Math.PI);
return degrees;
}
stage.addEventListener(Event.ENTER_FRAME, rotateMC);
function rotateMC(event:Event):void {
var adjacent:Number = this.x - mouseX;
var opposite:Number = this.y - mouseY;
var angle:Number = Math.atan2(opposite, adjacent);
this.rotation = (convert(angle))-90;
}
}
}
Using A Custom Class
i am just starting to program and am making my own web site.
i have just converted the photoviewer tutorial into a custom class to be used as a function from my main fla file.
i have many layers in my fla file and other action script how can i asine it to a layer so i can view the photos
thanks
Xml In Custom Class
I apologize if this has been properly addressed somewhere but i'm starting to chase my tail on it so i think i have to post for help.
My true desire is to get [1] working below but i can't figure why any information given to PROPS is not retained in the xml load method...even if its static. When i use the Properties class i always get 'Reading xml...' whether I use [1] or [2]. At first i thought it wasn't even being invoked until i did [3] and saw that infact it was.
What am I doing wrong? Thx in advance.
ActionScript Code:
class Properties {
var PROPS:Object = new Object();
var xml:XML;
public function loadProperties( file:String ) :Void {
PROPS["SOME_VAR"]="Reading xml...";
/* load config file */
xml = new XML();
xml.ignoreWhite = true;
xml.load( file );
xml.onLoad = mx.utils.Delegate.create(this, xmlLoaded);
}
function xmlLoaded( success:Boolean ) {
if ( success ) {
//PROPS[xml.childNodes[0].childNodes[0].nodeName]=xml.childNodes[0].childNodes[0].firstChild.nodeValue; // [1]
//PROPS["SOME_VAR"]="Success loading xml"; // [2]
_root.debugTxt=xml.childNodes[0].childNodes[0].firstChild.nodeValue; // [3]
}
}
}
Custom Class
Howdy fella geeks,
Check out this code:
var mc:MovieClip = new MovieClip()
mc. <-- after I type . (dot) it shows me a drop down menu with all the public functions/properties
But if I create a custom class called "bike" and try the same thing, when I type . (dot) it doesn't show me a drop down menu with all the public functions/properties.
var b:bike = new bike();
b. <-- this shows me nothing
What am I doing wrong? var b:bike = new bike(); works so I know it sees my class, but it's not seeing the public stuff.
Thanks
tk
Attach Code
package {
public class bike {
public var speed:Number;
public function forward() {
}
public function backward() {
}
}
}
Custom Class
I have developed two custom classes that extend the movie clip class. They first class (Table) draws a cool table and attaches Row objects to it which display the data. This is one part of a larger project.
There is a method inside the Table class clearRow() that fades all the rows out one by one then removes the Table object. This works fine the first time the class is instantiated; however, the second time the clearRow() functions fades and removes the whole stage. If anyone could tell me what is going on I'd be very grateful. Source files attached. Thank you all.
Custom Class
Trying to learn how to make custom classes. Just want to have two functions from the class. One to fade a mc(circle_mc) out and another to fade it back in again. I can get the class to trace to the fla file but can't get the movieclip to tween at all.
import mx.transitions.Tween;
import mx.transitions.easing.Regular;
import mx.transitions.easing.Strong;
==================class file==================== .....
XML In Custom Class?
why wouldn't this work as an AS2.0 class? the 'myXml' value always comes up undefined. i've established that it is loading the xml file and i've tried local and online xml files and i'm just stuck... i'm new to class building.
thanks for your help.
the as file...
Code:
class com.news.newsXML
{
//
private var myXml:XML;
//
public function newsXML()
{
init();
}
//
private function init():Void
{
trace("init();");
myXml = new XML();
myXml.ignoreWhite = true;
myXml.onLoad = parseNews;
myXml.load("any.xml");
}
//
private function parseNews():Void
{
trace("Function: parseNews();");
trace("myXml == " + myXml);
}
}
in the fla...
Code:
import com.news.newsXML;
var newsObj:newsXML = new newsXML();
Custom Class
I'm trying to write my first custom class and I am having a few problems with it. If anyone could point out where my problems are or give a link to a good resource on learning more about custom classes that would be wonderful.
Code:
class spawnTextFields {
public function spawnTextFields(target:String,txtName:String,depth,xLoc,yLoc,setStr:String){
if(depth == null){
depth = this.getNextHighestDepth();
}
target.createTextField([txtName],[depth],0,0,0,0);
target.txtName.text = [setStr];
target.txtName.autoSize=true;
}
}
When I run that I get the following errors:
There is no method with the name 'getNextHighestDepth'.
AS 3 Custom Class
I have been trying to convert the code posted previously to a custom class:
Code:
package {
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.display.Stage;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.display.StageDisplayState;
import flash.accessibility.AccessibilityProperties;
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextLineMetrics;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
//----------------------------------------------------------------
import flash.utils.getDefinitionByName;
import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.media.SoundChannel;
//----------------------------------------------------------------
var stage:Stage;
var content_tb:TextField;
var xmlLoader:URLLoader;
//----------------------------------------------------------------
stage.displayState = StageDisplayState.FULL_SCREEN;
stage.scaleMode = StageScaleMode.NO_SCALE;
//----------------------------------------------------------------
content_tb.embedFonts = true;
content_tb.selectable = false;
//----------------------------------------------------------------
var clickSound:Sound;
var librarySoundOne:Class = getDefinitionByName ( "Click" ) as Class;
clickSound = new librarySoundOne();
var clickChannel:SoundChannel;
//----------------------------------------------------------------
var dingSound:Sound;
var librarySoundTwo:Class = getDefinitionByName ( "Ding" ) as Class;
dingSound = new librarySoundTwo();
var dingChannel:SoundChannel;
//----------------------------------------------------------------
public class LoadXML extends MovieClip {
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("xml/modernism.xml"));
// Constructor
public function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
LoadContent(xmlData);
}
// Method invoked automatically when the XML finishes loading
function LoadContent(textData:XML):void {
//CONTENT TO BE DISPLAYED ON INITIAL LOAD
var defaultText = textData.item[0].content.text();
var pageTitle_text = textData.item.label.text()[0];
pageTitle_tb.htmlText = "<b>" + pageTitle_text + "</b>";
var formatSpacing:TextFormat = new TextFormat();
formatSpacing.letterSpacing = 4;
pageTitle_tb.setTextFormat(formatSpacing);
//----------------------------------------
function setPage(page:Number):void {
field.scrollV = (page - 1) * linesPerPage + 1;
}
// Assigns the text field that is on the stage to a local variable
var field:TextField = content_tb;
field.embedFonts = true;
// Assign the content to the text field
field.htmlText = defaultText;
// Extracts the text format and line height properties
var format:TextFormat = field.getTextFormat();
var leading = int(format.leading);
var extent:TextLineMetrics = field.getLineMetrics(0);
var ascent = extent.ascent;
var descent = extent.descent;
// CALCULATE THIS NUMBER USING BODY TEXT OF THE SAME FONT SIZE
// IF HTML TEXT INCLUDES HEADINGS OF DIFFERING SIZES THE NUMBERS WILL BE SKEWED
//var lineHeight = ascent + descent + leading;
var lineHeight = 16;
var linesPerPage = Math.floor((field.height - 4 + leading) / lineHeight);
var lineCount = (field.maxScrollV - 1) + linesPerPage;
var pageCount = Math.ceil(lineCount / linesPerPage);
var offset = (linesPerPage * pageCount) - lineCount + 1;
var lineBreak:String = "<br />";
//var lineBreak:String = "
";
for (var i = 0; i < offset; i++) {
defaultText.htmlText += lineBreak;
}
//LINE BELOW IS A NECESSARY REPEAT
field.htmlText = defaultText;
var panelNum = pageCount;
var curNum = 1;
pageNum.htmlText = "<b>" + curNum + "</b>";
pageTotal.htmlText = "<b>" + panelNum + "</b>";
prevButton_mc.visible = false;
function NextOnClick(event:MouseEvent):void {
curNum++;
pageNum.htmlText = "<b>" + curNum + "</b>";
setPage(curNum);
if (curNum == 2) {
prevButton_mc.visible = true;
clickChannel = clickSound.play();
} else if (curNum == panelNum) {
event.currentTarget.visible = false;
curNum = panelNum;
dingChannel = dingSound.play();
} else {
clickChannel = clickSound.play();
}
}
nextButton_mc.buttonMode = true;
nextButton_mc.addEventListener(MouseEvent.CLICK, NextOnClick);
function PrevOnClick(event:MouseEvent):void {
curNum--;
pageNum.htmlText = "<b>" + curNum + "</b>";
setPage(curNum);
if (curNum == 1) {
setPage(curNum);
event.currentTarget.visible = false;
curNum = 1;
dingChannel = dingSound.play();
} else {
clickChannel = clickSound.play();
}
nextButton_mc.visible = true;
}
prevButton_mc.buttonMode = true;
prevButton_mc.addEventListener(MouseEvent.CLICK, PrevOnClick);
}
}
}
I've managed to eliminate all the errors except one:
Code:
1067: Implicit coercion of a value of type Class to an unrelated type Function.
That error refers to the following line:
Code:
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
The compiler doesn't like the name of the public function I guess. Shouldn't the public function name be the same as it's class name? Hopefully someone can spot the issue. (I'm sure I'll get a whole other group of errors once this is fixed)
[Q] Custom Class
Hello Children of the Lee,
I'm writing a Tile Class that allows you to apply a tiled background that, at the moment, using an image from your library. I was doing well until i ran a couple of tests...Code:
import net.actionscriptblog.drawing.Tile
// Usage 1: fill stage
var bkg:Tile = new Tile();
bkg._id = 'tile1.gif';
bkg._width = Stage.width;
bkg._height = Stage.height;
bkg._clip = this;
bkg.fill();
// Usage 2: with equal margins
var layer1:Tile = new Tile();
layer1._id = 'tile2.gif';
layer1._width = Stage.width - 10;
layer1._height = 60;
layer1._margin = 10;
layer1._clip = this.createEmptyMovieClip('layer1_mc', this.getNextHighestDepth());
layer1.fill();
...which works like butter but when i add the third tile, no matter the properties, no matter if is switch layer1 & layer2, that third tile gets screwed up...Code:
// Usage 3: with different margins
var layer2:Tile = new Tile();
layer2._id = 'tile3.gif';
layer2._width = 100;
layer2._height = 300;
layer2._left = 10;
layer2._top = 100;
layer2._clip = this.createEmptyMovieClip('layer2_mc', this.getNextHighestDepth());
layer2.fill();
... it seems to that my code does not allow you to add more than two tiles.... here's a snippet of my ClassCode:
import flash.display.BitmapData;
//import mx.managers.DepthManager;
class net.actionscriptblog.drawing.Tile
{
// variables
private var tile:BitmapData;
private var stage:Boolean;
private var movieclip:MovieClip;
// properties
public var id:String;
public var width:Number;
public var height:Number;
public var clip:MovieClip;
// default properties
public var margin:Number = 0;
public var left:Number = 0;
public var top:Number = 0;
// constructor
public function Tile (linkage_id:String, movieclip:MovieClip, width_num:Number, height_num:Number, left_num:Number, top_num:Number)
{
if (arguments.length != 0)
{
// set properties
this.id = linkage_id;
this.width = width_num;
this.height = height_num;
this.clip = movieclip;
if (left_num != undefined) this.left = left_num;
if (top_num != undefined) this.top = top_num;
}
else
{
// do nothing
}
}
public function fill(width_num:Number, height_num:Number, marginLeft_num:Number, marginTop_num:Number)
{
if (arguments.length != 0)
{
this.clip.beginBitmapFill(tile);
this.clip.moveTo(margin_left, margin_top);
this.clip.lineTo(width_num, margin_top);
this.clip.lineTo(width_num, height_num);
this.clip.lineTo(margin_left, height_num);
this.clip.lineTo(margin_left, margin_top);
this.clip.endFill();
}
else
{
this.clip.beginBitmapFill(tile);
this.clip.moveTo(this.left, this.top);
this.clip.lineTo(this.width, this.top);
this.clip.lineTo(this.width, this.height);
this.clip.lineTo(this.left, this.height);
this.clip.lineTo(this.left, this.top);
this.clip.endFill();
}
}
}
I'm I going to need the Delegate or the DepthManager Class?
Please Help Me With Custom XML Class
Hi all,
I have a problem, I'm writing custom class, witch should load XML data:
Code:
package le1
{
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLVariables;
import mx.controls.Alert;
public class myReadXMLClass extends Sprite
{
public var selfImage:String;
public var pictUrl:Array = new Array(4);
public var rotate:Array = new Array(4);
public var ident:Array = new Array(4);
public var arrowVisible:Array = new Array(4);
public var loaderBuffer:Array = new Array(4);
public var loaded:Boolean = false;
private var req:URLRequest = new URLRequest();
private var vars:URLVariables = new URLVariables();
private var loader:URLLoader = new URLLoader();
private var My_XML:XML;
public function readXML(file:String, sceneID:String):void
{
// Setting up URL addres given to function
req.url = file;
// Send variables to php, to get valid xml file.
vars.id = sceneID;
// Sending data with php_request.
req.data = vars;
req.method = URLRequestMethod.POST;
// Getting inforamtion from php file.
loader.addEventListener(Event.COMPLETE, xmlLoaded);
loader.load(req);
}
private function xmlLoaded(e:Event):void
{
try
{
My_XML = new XML(loader.data); //Putting XML resolved by PHP in AS3 XML
selfImage = My_XML.self_image;
pictUrl[1] = My_XML.arrow1.pict_url; rotate[1] = My_XML.arrow1.rotation;
pictUrl[2] = My_XML.arrow2.pict_url; rotate[2] = My_XML.arrow2.rotation;
pictUrl[3] = My_XML.arrow3.pict_url; rotate[3] = My_XML.arrow3.rotation;
pictUrl[4] = My_XML.arrow4.pict_url; rotate[4] = My_XML.arrow4.rotation;
ident[1] = My_XML.arrow1.id; arrowVisible[1] = My_XML.arrow1.visible;
ident[2] = My_XML.arrow2.id; arrowVisible[2] = My_XML.arrow2.visible;
ident[3] = My_XML.arrow3.id; arrowVisible[3] = My_XML.arrow3.visible;
ident[4] = My_XML.arrow4.id; arrowVisible[4] = My_XML.arrow4.visible;
loaded = true;
dispatchEvent(new Event(Event.COMPLETE));
}
catch(e:Error)
{
Alert.show("Error:"+e.message);
}
}
public function isLoaded():Boolean
{
return loaded;
}
}
}
but when I'm using my class like this:
Code:
var readMyXML:myReadXMLClass = new myReadXMLClass();
readMyXML.readXML(phpFile, scene_id);
var ar:Boolean = readMyXML.isLoaded();
The variable ar is always false, why ?
Help Using A Custom Class
The class works exactly how its supposed to. I want to add a listener to check for stage resize and then run positionInterface. I haven't worked much with classes but I got through the tedious part.
Code:
class com.130public.utils.interfacePosition extends MovieClip {
// ** VARIABLES **
// Constants:
public static var Padding:Number = 5;
// Public Properties:
public var stageWidth:Number = Stage.width;
public var stageHeight:Number = Stage.height;
public var myListener;
// Private Properties:
private var Width:Number;
private var Height:Number;
private var Xcenter:Number;
private var Ycenter:Number;
//left panel
private var lPanelX:Number;
private var lPanelY:Number;
private var lPanelWidth:Number;
//top panel
private var tPanelX:Number;
private var tPanelY:Number;
private var tPanelHeight:Number;
//right panel
private var rPanelX:Number;
private var rPanelY:Number;
private var rPanelWidth:Number;
//bottom panel
private var bPanelX:Number;
private var bPanelY:Number;
private var bPanelHeight:Number;
//main panel
private var mainX:Number;
private var mainY:Number;
private var mainHeight:Number;
private var mainWidth:Number;
// ** UI ELEMENTS **
private var bg:MovieClip;
private var main:MovieClip;
private var lPanel:MovieClip;
private var tPanel:MovieClip;
private var rPanel:MovieClip;
private var bPanel:MovieClip;
// ** UI EVENTS **
// Initialization:
private function Main() {
}
private function onLoad():Void {
configUI();
}
// Public Methods:
public function positionInterface():Void {
//set lPanel to left of MC and centers with the height of MC
lPanel._x = (0 + Padding);
lPanel._y = ((stageHeight / 2) - lPanelY);
//set tPanel to top of MC and centers with the width of MC
tPanel._x = ((stageWidth / 2) - tPanelX);
tPanel._y = (0 + Padding);
//set rPanel to right of MC and centers with the height of MC
rPanel._x = ((stageWidth - rPanelWidth) - Padding);
rPanel._y = ((stageHeight / 2) - rPanelY);
//set tPanel to bottom of MC and centers with the width of MC
bPanel._x = ((stageWidth / 2) - bPanelX);
bPanel._y = ((stageHeight - bPanelHeight) - Padding);
//set main to center of MC
main._x = ((stageWidth / 2) - mainX);
main._y = ((stageHeight / 2) - mainY);
}
// Private Methods:
private function getYcenter(eventObj:Object):Void {
eventObj.Ycenter = (eventObj._height / 2);
}
private function getXcenter(eventObj:Object):Void {
eventObj.Xcenter = (eventObj._width / 2);
}
private function configUI():Void {
getYcenter(lPanel);
lPanelY = lPanel.Ycenter;
//
getXcenter(tPanel);
tPanelX = tPanel.Xcenter;
//
rPanelWidth = rPanel._width;
getYcenter(rPanel);
rPanelY = rPanel.Ycenter;
//
bPanelHeight = bPanel._height;
getXcenter(bPanel);
bPanelX = bPanel.Xcenter;
//
getYcenter(main);
mainY = main.Ycenter;
getXcenter(main);
mainX = main.Xcenter;
//
positionInterface();
}
}
Does anyone have any clue.
Code:
import com.antalmedia.utils.interfacePosition;
Stage.scaleMode = "noScale"
var stageListener:Object = new Object();
stageListener.onResize = function () {
trace("Stage size is " + Stage.width + " by " + Stage.height);
positionInterface();
}
Stage.addListener(stageListener);
I thought adding something like this on the frame the mc was used might do it but... no
Importing Class Files
I have a project that is importing class files and it works great on the PC side, but when I move it over to the Mac side and try to complile it I get lots of errors in regards to being unable to load the class files. I'm using Flash MX 2004 Professional. and I have ensure that it is using actionScript 2.0 anybody ever experience this? Any suggestions? Thank you.
Importing Class Speed
Does importing classes like this:
Code:
import flash.media.Sound;
import flash.media.SoundChannel;
make flash run faster than if they were imported like this:
Code:
import flash.media.*;
Thanks.
[CS3] Weight Of Class Importing
Hi,
I am wondering how exactly is made the import of classes; I know that Flash imports only those which are used, but if for instence you have say 3 functions in one Class, but you only need to use one of these functions, does Flash import the two others too?
That could affect the swf weight...
Importing A Swf Linked To A Class
Hello, I hope you could help me because i am really stuck into it:
I have a scroll file, taken from a tutorial, which is linked to a class. After having customized my file I did try it and it works fine. The problem is starting when I try to import this file to an empty MCL in my website. When I have imported all the elements they do not respond and act like single pieces (es. the scroll bar is detached from the scroller). What can I do? I am attaching all the codes and I hope you can help me .
thank you so much
p.s all the classes and the file are in the same directory
ActionScript Code:
//this is the scroll class//
/**
* Flashscaper Scrollbar Component
* Customizable Scrollbar
*
* @author Li Jiansheng
* @version 1.0.0
* @private
* @website [url]http://www.flashscaper[/url]
*/
package {
import caurina.transitions.*;
import flash.display.*;
import flash.events.*;
import flash.geom.*;
public class Scrollbar extends MovieClip {
private var target:MovieClip;
private var top:Number;
private var bottom:Number;
private var dragBot:Number;
private var range:Number;
private var ratio:Number;
private var sPos:Number;
private var sRect:Rectangle;
private var ctrl:Number;//This is to adapt to the target's position
private var trans:String;
private var timing:Number;
private var isUp:Boolean;
private var isDown:Boolean;
private var isArrow:Boolean;
private var arrowMove:Number;
private var upArrowHt:Number;
private var downArrowHt:Number;
private var sBuffer:Number;
public function Scrollbar():void {
scroller.addEventListener(MouseEvent.MOUSE_DOWN, dragScroll);
stage.addEventListener(MouseEvent.MOUSE_UP, stopScroll);
stage.addEventListener(MouseEvent.MOUSE_WHEEL,mouseWheelHandler);
}
//
public function init(t:MovieClip, tr:String,tt:Number,sa:Boolean,b:Number):void {
target = t;
trans = tr;
timing = tt;
isArrow = sa;
sBuffer = b;
if (target.height <= track.height) {
this.visible = false;
}
//
upArrowHt = upArrow.height;
downArrowHt = downArrow.height;
if (isArrow) {
top = scroller.y;
dragBot = (scroller.y + track.height) - scroller.height;
bottom = track.height - (scroller.height/sBuffer);
} else {
top = scroller.y;
dragBot = (scroller.y + track.height) - scroller.height;
bottom = track.height - (scroller.height/sBuffer);
upArrowHt = 0;
downArrowHt = 0;
removeChild(upArrow);
removeChild(downArrow);
}
range = bottom - top;
sRect = new Rectangle(0,top,0,dragBot);
ctrl = target.y;
//set Mask
isUp = false;
isDown = false;
arrowMove = 10;
if (isArrow) {
upArrow.addEventListener(Event.ENTER_FRAME, upArrowHandler);
upArrow.addEventListener(MouseEvent.MOUSE_DOWN, upScroll);
upArrow.addEventListener(MouseEvent.MOUSE_UP, stopScroll);
//
downArrow.addEventListener(Event.ENTER_FRAME, downArrowHandler);
downArrow.addEventListener(MouseEvent.MOUSE_DOWN, downScroll);
downArrow.addEventListener(MouseEvent.MOUSE_UP, stopScroll);
}
var square:Sprite = new Sprite();
square.graphics.beginFill(0xFF0000);
square.graphics.drawRect(target.x, target.y, target.width+5, (track.height+upArrowHt+downArrowHt));
parent.addChild(square);
target.mask = square;
}
public function upScroll(event:MouseEvent):void {
isUp = true;
}
public function downScroll(event:MouseEvent):void {
isDown = true;
}
public function upArrowHandler(event:Event):void {
if (isUp) {
if (scroller.y > top) {
scroller.y-=arrowMove;
if (scroller.y < top) {
scroller.y = top;
}
startScroll();
}
}
}
//
public function downArrowHandler(event:Event):void {
if (isDown) {
if (scroller.y < dragBot) {
scroller.y+=arrowMove;
if (scroller.y > dragBot) {
scroller.y = dragBot;
}
startScroll();
}
}
}
//
public function dragScroll(event:MouseEvent):void {
scroller.startDrag(false, sRect);
stage.addEventListener(MouseEvent.MOUSE_MOVE, moveScroll);
}
//
public function mouseWheelHandler(event:MouseEvent):void {
if (event.delta < 0) {
if (scroller.y < dragBot) {
scroller.y-=(event.delta*2);
if (scroller.y > dragBot) {
scroller.y = dragBot;
}
startScroll();
}
} else {
if (scroller.y > top) {
scroller.y-=(event.delta*2);
if (scroller.y < top) {
scroller.y = top;
}
startScroll();
}
}
}
//
public function stopScroll(event:MouseEvent):void {
isUp = false;
isDown = false;
scroller.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_MOVE, moveScroll);
}
//
public function moveScroll(event:MouseEvent):void {
startScroll();
}
public function startScroll():void {
ratio = (target.height - range)/range;
sPos = (scroller.y * ratio)-ctrl;
Tweener.addTween(target, {y:-sPos, time:timing, transition:trans});
}
}
}
//this is the AS that I am using in my scroll file//
sb.init(images_mc, "easeOutBack",2,true,2);
//this is the file script to import the swf into an empty mcl"
import LoaderExample;
var loadedAsset:LoaderExample = new LoaderExample('tee.swf');
holder.addChild(loadedAsset)
Importing Class Causes Freeze
here's the code, on the swf's _root:
import com.website.package.Application;
//Application.Main( this, "Menu" );
even with the second line commented out, we get a big freeze, whole seconds of wait. the movie just completely stops playing, even an onEnterFrame method on the _root won't run until the import is finished. just nothing but waiting for the code to import. Application.as links off to an MVC architecture with a whole bunch of additional classes etc. and the inclusion of this line is enough to turn a 3K swf into a 443K swf.
erk! what can you do about that?!?!?
r
Importing Class Packages
i am currently developing a flash movie with no graphics at the moment. It is being done with a lot of classes and packages, many of the AS classes import the same packages as well. I have many linked movie clips to those classes.
The problem is that when i compile it takes quite a long time. I want to know if there is a way to have a single file for all my classes (like an include file) as opposed to having a dozen import lines of code in each AS script.
Importing A Swf Linked To A Class
Hello, I hope you could help me because i am really stuck into it:
I have a scroll file, taken from a tutorial, which is linked to a class. After having customized my file I did try it and it works fine. The problem is starting when I try to import this file to an empty MCL in my website. When I have imported all the elements they do not respond and act like single pieces (es. the scroll bar is detached from the scroller). What can I do? I am attaching all the codes and I hope you can help me .
thank you so much
p.s all the classes and the file are in the same directory
Attach Code
//this is the scroll class//
/**
* Flashscaper Scrollbar Component
* Customizable Scrollbar
*
* @authorLi Jiansheng
* @version1.0.0
* @private
* @website http://www.flashscaper
*/
package {
import caurina.transitions.*;
import flash.display.*;
import flash.events.*;
import flash.geom.*;
public class Scrollbar extends MovieClip {
private var target:MovieClip;
private var top:Number;
private var bottom:Number;
private var dragBot:Number;
private var range:Number;
private var ratio:Number;
private var sPos:Number;
private var sRect:Rectangle;
private var ctrl:Number;//This is to adapt to the target's position
private var trans:String;
private var timing:Number;
private var isUp:Boolean;
private var isDown:Boolean;
private var isArrow:Boolean;
private var arrowMove:Number;
private var upArrowHt:Number;
private var downArrowHt:Number;
private var sBuffer:Number;
public function Scrollbar():void {
scroller.addEventListener(MouseEvent.MOUSE_DOWN, dragScroll);
stage.addEventListener(MouseEvent.MOUSE_UP, stopScroll);
stage.addEventListener(MouseEvent.MOUSE_WHEEL,mouseWheelHandler);
}
//
public function init(t:MovieClip, tr:String,tt:Number,sa:Boolean,b:Number):void {
target = t;
trans = tr;
timing = tt;
isArrow = sa;
sBuffer = b;
if (target.height <= track.height) {
this.visible = false;
}
//
upArrowHt = upArrow.height;
downArrowHt = downArrow.height;
if (isArrow) {
top = scroller.y;
dragBot = (scroller.y + track.height) - scroller.height;
bottom = track.height - (scroller.height/sBuffer);
} else {
top = scroller.y;
dragBot = (scroller.y + track.height) - scroller.height;
bottom = track.height - (scroller.height/sBuffer);
upArrowHt = 0;
downArrowHt = 0;
removeChild(upArrow);
removeChild(downArrow);
}
range = bottom - top;
sRect = new Rectangle(0,top,0,dragBot);
ctrl = target.y;
//set Mask
isUp = false;
isDown = false;
arrowMove = 10;
if (isArrow) {
upArrow.addEventListener(Event.ENTER_FRAME, upArrowHandler);
upArrow.addEventListener(MouseEvent.MOUSE_DOWN, upScroll);
upArrow.addEventListener(MouseEvent.MOUSE_UP, stopScroll);
//
downArrow.addEventListener(Event.ENTER_FRAME, downArrowHandler);
downArrow.addEventListener(MouseEvent.MOUSE_DOWN, downScroll);
downArrow.addEventListener(MouseEvent.MOUSE_UP, stopScroll);
}
var square:Sprite = new Sprite();
square.graphics.beginFill(0xFF0000);
square.graphics.drawRect(target.x, target.y, target.width+5, (track.height+upArrowHt+downArrowHt));
parent.addChild(square);
target.mask = square;
}
public function upScroll(event:MouseEvent):void {
isUp = true;
}
public function downScroll(event:MouseEvent):void {
isDown = true;
}
public function upArrowHandler(event:Event):void {
if (isUp) {
if (scroller.y > top) {
scroller.y-=arrowMove;
if (scroller.y < top) {
scroller.y = top;
}
startScroll();
}
}
}
//
public function downArrowHandler(event:Event):void {
if (isDown) {
if (scroller.y < dragBot) {
scroller.y+=arrowMove;
if (scroller.y > dragBot) {
scroller.y = dragBot;
}
startScroll();
}
}
}
//
public function dragScroll(event:MouseEvent):void {
scroller.startDrag(false, sRect);
stage.addEventListener(MouseEvent.MOUSE_MOVE, moveScroll);
}
//
public function mouseWheelHandler(event:MouseEvent):void {
if (event.delta < 0) {
if (scroller.y < dragBot) {
scroller.y-=(event.delta*2);
if (scroller.y > dragBot) {
scroller.y = dragBot;
}
startScroll();
}
} else {
if (scroller.y > top) {
scroller.y-=(event.delta*2);
if (scroller.y < top) {
scroller.y = top;
}
startScroll();
}
}
}
//
public function stopScroll(event:MouseEvent):void {
isUp = false;
isDown = false;
scroller.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_MOVE, moveScroll);
}
//
public function moveScroll(event:MouseEvent):void {
startScroll();
}
public function startScroll():void {
ratio = (target.height - range)/range;
sPos = (scroller.y * ratio)-ctrl;
Tweener.addTween(target, {y:-sPos, time:timing, transition:trans});
}
}
}
//this is the AS that I am using in my scroll file//
sb.init(images_mc, "easeOutBack",2,true,2);
//this is the file script to import the swf into an empty mcl"
import LoaderExample;
var loadedAsset:LoaderExample = new LoaderExample('tee.swf');
holder.addChild(loadedAsset);
Importing Tween Class
hi,
ok i get an error when i try to import the tween class or easing
it says that there is a problem with a class name that it is already being imported?
anyone?
thanks
aldo
Issue With Importing Class
Hi there,
I'm having some problems importing a class, the message that Flash gives me is this;
[i]"The class being compiled, 'ImageLoader', does not match the class that was imported, 'com.martijndevisser.ImageLoader'.
Issue With Importing Class
Hi there,
I'm having some problems importing a class, the message that Flash gives me is this;
The class being compiled, 'ImageLoader', does not match the class that was imported, 'com.martijndevisser.ImageLoader'.
The only line of code in my flash movie is this:
import com.martijndevisser.*;
And yes, the class is in that folder
The class is from here: http://www.martijndevisser.com/download/ImageLoader.as
I've used the class before and it works fine, I just dont know what to do?
Any ideas? Thanks
|