Custom Class Pointers
Hi,
Ok, so I've got my head around AS3 from a procedural approach, but I now want to write more code in class form.
As I do a bit with XML, I've written this little class for handling XML URL requests. Basically you pass it a url and a call back function you want notified when the XML is loaded. Similar to what you can do using the built in URL loader classes etc. I wanted to achieve that "Black Box" approach however, when I just have to create a new instance of a class and pass it the info I want, getting back what I want, without having to edit the class each time I want to pass it a different XML file url.
So, looking at the below, am I on the right track with this approach. This is the first AS3 class I have attempted to write.
Here is the class:
PHP Code:
package { import flash.display.Sprite; import flash.display.Loader; import flash.events.*; import flash.net.URLRequest; import flash.net.URLLoader;
public class loadXml extends Sprite { public var myXML:XML; public var myXLoader:URLLoader private var myXMLURL:URLRequest private var XML_URL:String public function loadXml(url:String, callBack:Function) { myXML = new XML(); XML_URL = url; myXMLURL = new URLRequest(XML_URL); myXLoader = new URLLoader(myXMLURL); myXLoader.addEventListener("complete", callBack); } } }
And here is how I instantiate it and use it on the main timeline or in my documents class etc.
PHP Code:
var testXML:XML = new XML(); var myloadXml:loadXml = new loadXml("gallery1.xml", checkLoad)
function checkLoad(evt:Event){ testXML = XML(evt.target.data) trace(testXML)//outputs raw XML data, to be accessed how you see fit. }
Things I have yet to figure out, are simply passing the class a var that the class will add the XML data to for me, and destroying the class event listener I create for the loading complete event.
KirupaForum > Flash > ActionScript 3.0
Posted on: 09-12-2007, 07:35 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Custom Mouse Pointers
How do i change mouse pointers? example: i want my own mouse pointer instead of the usual mouse pointer that comes with flash. also when i rollover on a button i need a custom pointer for that, and when i start to drag i need a custom pointer for that too. im new to actionscript. a little help is much appreciated. thanks
Custom Mouse Pointers
Hi guys... custom mouse pointers...
Here's something I would love to use, yet being a perfectionist, I have only been able to use them successfully in Projectors. Here is why:
There are two ways to produce the custom mouse, one involves the startDrag method and the other simply places the new pointer MC at the root x and y co-ords. Either method works the same, however it should be noted that the using the startDrag method means you will not be able to drag anything else with this pointer (not a huge drawback, but an important one if your site is going to have a draggable MC somewhere).
The big problem with either of these methods is the way Flash positions the new pointer if you move outside the SWF (usually seen when the SWF is embedded in a HTML page). If the mouse moves outside the SWF's boundary, the new pointer will simply stop where the mouse was last recognised as being inside. This in itself is ugly, but confusingly creates two mouse pointers (one stationary inside the SWF and one you are controlling outside). My aim is to hide the flash pointer when leaving the SWF.
My first thought was to measure when the pointer had left the SWF boundary by using the root x & y co-ords, then showing and hiding as appropriate... but unfortunately flash will only detect mouse coords while inside the SWF, so it is impossible to effectively judge when the mouse leaves (pointers leaving confuse SWF's because they only detect where the pointer was previous to leaving, and a large mouse movement can make flash believe the pointer is still 50+ pixels inside the SWF).
A solution therefore lies elsewhere, I'm just a little lost as to where... anyone know of a condition within actionscript which detects when the mouse is over the whole movie?
Actionscript Pointers? (not Mouse Pointer, I'm Talking About C++ Style Pointers)
okay, so i have a function that i want to manipulate the global variables x and y in this way:
var x:Number = 45;
var y:Number = 32;
manipulate(x,y); //some stuff goes on here
trace(x+" "+y); //this will show completely different numbers in both X and Y.
how would you go about making such a function? and how would you use it?
thanks!
[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.
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
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);
}
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.
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 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
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
Destructor For Custom Class
Hi guys,
I have a interesting question for you.
How can I destruct a custom created object in flash 5 at runtime?
Meaning, I have created a custom object and I don't need it anymore because it finished doing what I want and I want to destroy it so it does not occupy memory any more.
Custom Class Of MovieClips?
I am trying to program a hexagonal chess game. I think I need a class of "cell" movieClips than have custom properties, like "rank" and "file" and "occupied," etc. How can I create a custom class of movieClip objects with custom properties (so that I can access them in my MovieClip library)?
Problems With My Custom Class
Im making a scrollbar for Flash 5 and I came up with the following class so far. This code is on the only frame of my timeline, and the only thing in the movie is a scrollbar in stage (just a collection of clips not yet doing anything).
Code:
Scrollbar = function () {
this.init();
}
Scrollbar.prototype = new MovieClip();
Scrollbar.prototype.init = function () {
// Set vars
this.isScrollbar = true;
// Call functions
this.refreshElements();
}
Scrollbar.prototype.refreshElements = function () {
if (this.orientation == "vertical") {
trace ("vertical");
} else if (this.orientation == "horizontal") {
trace ("horizontal");
}
}
My scrollbar is a smart clip, with two parameters 'orientation' and length. The first and only frame of my scrollbars timeline has the line of code:
Code:
this = new _root.Scrollbar();
Now my problem is that the prototype function 'refreshElements' in my class cant read the value of orientation from my scrollbar that is on stage, can any suggest a solution for this as Im pretty stuck.
This is my first attempt at classes in Flash 5, my previous attempts have been in MX.
Cheers for reading this, and any help you offer!
Custom Class Question
I have a method(init) in which I want to create an event for an object(back_mc) that is loacated inside this custom object.
How do I reference variables outside of this even within a custome class??? Any help would be great and I don't want to used and hidden button objects to accomplish this task.
CustomObject.prototype.init = function(){
//trace("hello")
this.backColor = new Color(this.back)
this.borderColor = new Color(this.borders)
this.backColor.setRGB(this.backColor_param)
this.borderColor.setRGB(this.borderColor_param)
this.UserName = this.UserName_param
this.UserAge = this.UserAge_param
this.back_mc.onRollOver = function(){
//how do I reference this.UserName indide of this movieClip event
trace(?????????)
}
}
Custom Class Scope?
I created a custom class on the root of _level0.
Code:
FXML = function ()
{
...
}
FXML.prototype.getValue = function (xPath)
{
...
}
I want the scope of my class to be in all the movieclip.
I don't want to have to this:
Code:
var myfxml = new _level0.FXML()
How can my custom class have a global scope like others Flash objects?
Use Xml Object In Custom Class
Hi, i hope someone can help me with this one.
i am trying to make a private function in a custom class which which imports a xml-file and turns it into an array. Sofar i haven´t had any luck.
The code looks lige this:
private function loadXMLfile():Void {
obj_xml = new XML
obj_xml.ignoreWhite = true;
obj_xml.onLoad = function(success) {
var nbr_tracks:Number = this.obj_xml.firstChild.childNodes.length;
trace("test: " + nbr_tracks);
var i:Number;
for(i=0; i<nbr_tracks;i++){
this.arr_playlist[i] = this.obj_xml.firstChild.childNodes[i].attributes.name;
}
}
obj_xml.load("playliste.xml");
}
i can see the xml-content in the the output window when i run the movie, but it seems like it cannot be converted into an array. If i just use :
obj_xml = new XML("<playlist><track nbr='1' name='frosti.mp3' /><track nbr='2' name='test01.mp3' /><track nbr='3' name='test02.mp3' /></playlist>");
insted of importing the xml-file it works fine. Can someone help me please!?
/René
Why Are EVENTS Not Available In A Custom Class?
Code:
class clsCell {
// Some codes here which works.
// The event below does not work
this.onRelease = function() {
mutateMe();
}
}
I get this error:
This statement is not permitted in a class definition.
Can anybody let me know the syntax for creating enabling event handlers within a class?
Thanks
The Road To A Custom Class..
I am tired of always repeating my code as copy and paste and so therfore I would write a class to load my xml files and maybe a class to parse the data and leave me with an array of ojects or one object with array??? you get the point.
I figure wer'e all pretty much doing this a lot, and this is why exists XMLConnector component. But I wanted to be neater to not drag one onto the stage!
here we go
Code:
---------------------------------------------
import mx.data.components.*;
var timeInfo_con:XMLConnector=new XMLConnector();
var ds:DataSet=new DataSet();
timeInfo_con.URL="data.xml";
timeInfo_con.direction="receive";
timeInfo_con.ignoreWhite=true;
timeInfo_con.multipleSimultaneousAllowed = false;
timeInfo_con.suppressInvalidCalls = true;
//still need to bind the xml via component inspector
//
var listener:Object = new Object();
//
listener.result= function() {
trace(timeInfo_con.result);
};
timeInfo_con.addEventListener("result", listener);
timeInfo_con.trigger();
---------------------------------------------
this is returning undefined at present and were not even a class yet. Whats my problem?
thanks
mojito
Custom Class Problem
hi guys, i dont have too much experience using custom classes, anywayys i have this in "panel.as", and i have the AS 2.0 class set to "panel" in my movie. this is my button script in the movie, there could be something wrong with it as well.
Code:
panel2_mc._y=59;
panel1_mc.onPress=function(){
panel2_mc.panel(59,495,40)
}
basically my objective is to have panel2_mc move to a certain point and stop.
here is the custom class code in "panel.as"
Code:
class panel extends MovieClip {
function panel(startpos, endpos, speed) {
onEnterFrame = function () {
if (this._y == startpos) {
this._y += speed;
if (this._y>=endpos) {
this._y = endpos;
}
}
};
}
}
Custom Class Issue
Hi,
unless I'm going nuts, are top level classes such as Key and Math, NOT automatically accessible from a custom class? because that is what seems to be happening with what i'm working on. I have a class, it uses the Key class, but wasn't working as it was before (non OOP, AS1.0), and I realised i had to send the Key class as a parameter to the function in the custom class I created, then I wanted to do var *= 0.001; and my var EQUALLED 0.001 rather then being a fraction, so now i'm thinking I have to include the Math class as well? if so how?
thanks for any help
boombanguk
Custom Class Problem
Hi there..
okay I just make a simple class for my drag and drop stuff thingy...it seem's there is error for my array..it doesn't bring the value...so it keeps trace undefined....
here's are my currently code..sorry for the messy code..
Code:
class AttachMc{
var __holder:MovieClip;
var __holder2:MovieClip;
var __total:Number;
var targetArray:Array;
function AttachMc(holdermc:MovieClip,holdermc2:MovieClip,Total:Number){
this.__holder = holdermc;
this.__holder2 = holdermc2;
this.__total = Total;
targetArray = new Array();
attachTarget.apply(this);
attachDragger.apply(this);
}
public function attachTarget():Void{
for(var i:Number=0;i<__total;i++){
var mctarget:MovieClip = this.__holder.attachMovie("box","box"+i,3+i);
mctarget._x = 50+mctarget._width*i;
mctarget._y = 100;
mctarget.labeltarget.text = "target"+i;
targetArray.push(mctarget);
}
}
public function attachDragger():Void{
for(var j:Number=0;j<__total;j++){
var mcdragger:MovieClip = this.__holder2.attachMovie("dragger","dragger"+j,6+j);
mcdragger._x = 50+mcdragger._width*j;
mcdragger._y = 250;
mcdragger.labeldragger.text = "dragger"+j;
mcdragger.jvar = j;
mcdragger.onPress = function(){
this.startDrag();
}
mcdragger.onRelease = mcdragger.onReleaseOutside = function(){
this.stopDrag();
//trace targetArray return undefined
trace(targetArray);//output undefined
//the ideas is try to browse the array for detecting droping area..
for(var k:Number=0;k<targetArray.length;k++){
if(this.hitTest(targetArray[k])){
trace("u just hit");
}
}
}
}
}
}
Hope someone will point me or give me some shed on light on it..
any help are appreciate...
Thanks
|