Import New Classes In Swc?
Hello guys! I have this little problem, i have created a class and this class imports some classes, then the class has been exported as swc, so now i have a component but not always i will be using the classes inside the swc, sometimes i will create new classes and would like to have the swc implements those new and external classes too..... any ideas guys!
thanx in advance!!
FlashKit > Flash Help > Actionscript 3.0
Posted on: 08-25-2007, 12:38 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
When Is Necessary To Use Import Statements To Import Classes?
Hi,
I'm sure that it must be necessary to use import statements in some situations, I'm finding that my code often works fine without them. For example, some instructions will say it is necessary to use import.flash.events.MouseEvent; before MouseEvent.CLICK will work, or that I must import the loader class before loading an SWF, but I'm finding that I can skip timporting and it works fine. Could anyone please explain why this it, and give me some idea of how to knew when to import and when I don't have to?
Thank you in advance!
[F8] Import Classes
Im trying to import the JavaScript and Flash Intergration Kit class but when I create an instance of the JavaScriptProxy I get this error
Code:
**Error** C:Documents and Settingsadansky.SD5042DesktopJavaScript InterfaceactionscriptcommacromediajavascriptJavaScriptProxy.as: Line 67: The class being compiled, 'com.macromedia.javascript.JavaScriptProxy', does not match the class that was imported, 'actionscript.com.macromedia.javascript.JavaScriptProxy'.
{
here is my code
Code:
import actionscript.com.macromedia.javascript.*;
var proxy:JavaScriptProxy = new JavaScriptProxy(_root.lcId, this);
function addItem(item:Object):Void{
list.addItem(item);
};
function transferItemToJavaScript():Void{
if(list.selectedItem != null){
proxy.call("addItem", list.selectedItem);
list.removeItemAt(list.selectedIndex);
}
}
Import Classes
XML file:
<modifiers>
<modifier class="com.whitecitysoft.modifiers.Reverse">Revers ed</modifier>
<modifier class=" com.whitecitysoft.modifiers.Capitalize">Capitalize d</modifier>
<modifier class="com.whitecitysoft.modifiers.Scramble" >Scrambled</modifier>
</modifiers>
I have to load all of these classes and apply their effect on some string.Classes are .swf files in libs subfolder with package structure and they all contain one static method 'run'.
For example: public static run(text:String) : String
My code so far:
data = new XML();
data.ignoreWhite = true;
data.load("xml/modifiers.xml"); //ok
data.onLoad = function(success) {
if (success) {
if (data.status == 0) {
newClassArray = new Array();
l = data.childNodes[0].childNodes.length;
for (i=0; i<l; i++) {
newClassArray[i] = data.childNodes[0].childNodes[i].attributes["class"];
}
// problem with import
// this is just an example
var t:String = newClassArray[0].toString();
t = 'lib.'+t;
import t; // I can't load these classes
var my_string:String = 'This is a simple text.';
my_string = Reverse.run(my_string);
trace('Reversed: '+my_string);
} else {
trace("Parse Error:"+data.status);
}
} else {
// could not get the XML
trace("Load Error");
}
};
Cannot Import Some Classes
I am using Flash CS3. I have Flash installed in /Applications/CS3/Adobe Flash CS3. The box is a G4 MDD with adequate specifications.
Anyway, I have been experiencing issues with importing a few classes. I have been using a copy of the ActionScript 3.0 Language and Components Reference as detailed here:
http://livedocs.adobe.com/flash/9.0/...riptLangRefV3/
I am trying specifically to import fl.containers.ScrollPane and fl.control.TextArea. I import them as is normal:
import fl.control.TextArea;
fl.containers.ScrollPane;
And I am informed that every function I call is a reference to a possibly undefined function etc...
Could this be an issue with a improperly set classpath? My classpath is set as such:
"$(AppConfig)/ActionScript 3.0/Classes"
and
"."
Might it be the "." that is setting the thing off?
I am inclined to think not, because if I import, for instance, flash.display.MovieClip, it works perfectly.
Thanks for your help.
When To Import Classes?
I have a simple project in Flash CS3 where I've added an event listener to trigger a function at the end of an flv file (code attached). I kept getting the following error:
1046: Type was not found or was not a compile-time constant: VideoEvent.
Attach Code
stop();
myPlayback.x = (stage.stageWidth / 2) - (myPlayback.width / 2);
myPlayback.y = (stage.stageHeight / 2) - (myPlayback.height / 2);
//import fl.video.VideoEvent;
myPlayback.addEventListener(VideoEvent.COMPLETE, nextMovie);
function nextMovie(evt:VideoEvent):void
{
trace("Finally, you can go home!");
}
How To Import Some Classes?
I suppose I need to import an special class to use data types as integer, long or double from my own class. But i don't know what is the correct class I have to import?
Can you help me?
Why Import Classes?
stupid question #(how many posts do i have?),
although i can get around with oop as3, im wondering... say i write a class (lets call it Subclass) that is instantiated by another class (Mainclass). for what reasons would i need to actually do this?:
Code:
package
{
import Subclass;
public class Mainclass extends something
{
public function Mainclass()
{
var subclass = new Subclass();
}
}
}
i mean,i know that i can instantiate Subclass without importing it into Mainclass, but does importing give me some sort of advantages?
Importing Classes- Why Not Import Them All?
hi guys...i am playing with filters...now, to do this, i know i have import them
Code:
import flash.filters.DropShadowFilter //if it is a drop shadow
but this got me thinking...what are the negative effects of just importing ALL the filters
Code:
import flash.filters.*
will it make my swf big? slow?
[basic] Import Classes
Hi, I imported the class using the Document class field:
com.myname.Application
what about if I want to import other classes?
I tried with:
import com.myname.Application
but doesn't work...I'm a little bit confused! :|
How Can I Force Classes To Import?
I'm making a dynamic slideshow which is configurable via a php file. What I'm trying to allow is the ability to assign either Tween or 1 of the 9 transition classes (Blinds, Fly, Pixel Dissolve, etc.) to the slideshow via configurable variables in the php file.
I've come to find out that Flash doesn't automatically include these classes in the exported swf, but rather UPON export. My assumption is that is checks the AS for class definitions/constructors and imports only what it needs (to keep file size low). However, since this slideshow is dynamic, any type of transition will be needed.
What I need to do: FORCE any/all transition classes to be imported into the exported swf.
I've managed to force the easing classes (Bounce, Elastic, Strong, etc.) and apply them dynamically via this code in my Tween function:
ActionScript Code:
function transTween() {
import mx.transitions.Tween;
import mx.transitions.easing.*;
//
// force classes to be imported by using fake constructors
var force:Tween = new Tween(xxx, "_x", Back.easeOut, x, x, x, true);
var force:Tween = new Tween(xxx, "_x", Bounce.easeOut, x, x, x, true);
var force:Tween = new Tween(xxx, "_x", Elastic.easeOut, x, x, x, true);
var force:Tween = new Tween(xxx, "_x", Regular.easeOut, x, x, x, true);
var force:Tween = new Tween(xxx, "_x", Strong.easeOut, x, x, x, true);
var force:Tween = new Tween(xxx, "_x", None.easeNone, x, x, x, true);
//
eClass = new String(tParamAr[1]); // tParamAr[1] is the name of the easing class defined in the php file
eMeth = new String(tParamAr[2]); // tParamAr[2] is the name of the easing method defined in the php file
//
// {... deleted code, used to position movieclips based on loaded parameters ...}
//
tweenIn(1);
}
function tweenIn(num) {
var pTw:Tween = new Tween(imgWell["img"+num], tParamAr[0], mx.transitions.easing[eClass][eMeth], begin, midVal, duration, true);
pTw.onMotionFinished = function() {
ID = setInterval(tweenOut, delay, num);
};
}
//
function tweenOut(num) {
clearInterval(ID);
var pTw:Tween = new Tween(imgWell["img"+num], tParamAr[0], mx.transitions.easing[eClass][eMeth], midVal, finish, duration, true);
pTw.onMotionFinished = function() {
num++;
if (num>maxImages) {
num = 1;
}
tweenIn(num);
};
}
As seen in the code above, everything in the Tween constructor is dynamic. However, as I tried this with the Blinds transition, it failed to work properly.
ActionScript Code:
// 'tParamAr' is the array that contains the transition's paramaters
// this works
myTransitionManager.startTransition({type:Blinds, direction:Transition[direct], duration:tParamAr[1], easing:Strong[eMeth], numStrips:parseInt(tParamAr[4]), dimension:1});
// this doesn't
myTransitionManager.startTransition({type:Blinds, direction:Transition[direct], duration:tParamAr[1], easing:[eClass][eMeth], numStrips:parseInt(tParamAr[4]), dimension:parseInt(tParamAr[5])});
I've even gone so far as to include multiple TransitionManager constructors in a switch-case statement, but it seems to fail altogether if I have more then one constructor in my code.
Can't Import Two Classes At Same Time
I know it sounds weird, but I've not being able to import these two simple classes to a third one. I have simplified the code to bare traces and it still doesn't work. The strange thing is, if I import only ONE of the classes I hit control+T and presto, the error is gone, doesn't matter which one.
The three classes are in the same directory.
Any help would be greatly appreciated,
Thanks.
This is the main class (Three.as)
import One.as
import Two.as
class Three {
function Three(){
trace("Three");
}
}
---------------------------
(One.as)
class One {
function One(){
trace("One");
}
}
---------------------------
(Two.as)
class Two {
function Two(){
trace("Two");
}
}
Import Classes Strucutre
Is it possible to put my .as files in a folder and load the ones from another???
In the following folder is the class Example.
c:flashExampleClass
Code:
class Example {
public var nNumber:Number;
}
and I want to load the class "Example" from:
c:flash
so I thought I could do something like that:
Code:
import ExampleClass.Example;
class Another {
public var ex:Example;
}
Thanks
Import Classes Not Working
Today Flash decided to stop importing any of my classes. Everything worked fine yesterday. I came in today and it can't find anything. I know the files are there.
Code:
import com.mine.Test;
var t:Test = new Test();
Outputs "1172: Definition com.mine:Test could not be found.
Why I Have To Import Custom Classes
Code:
package {
import flash.display.*;
import example.test.Main;
public class Document extends MovieClip {
function Document() {
new example.test.Main();
}
}
}
it doesnt work without the 2nd import (import example.test.Main)
why is it so?
AS3 - What Is The Best Method To Know What Classes To Import
Does anyone know if there's a list or a chart that lists all of the built-in classes, and packages?
Basically, I want to be able to minimize the KB size of my movie - and instead of importing the entire text class for example (import flash.text.*) I want to import only the specific files that I need for that class. is there a simple way to list them, so I can pick and choose?
Import Classes Syntax Problem
I'm trying to import a class and all the classes in that directory. Here is my syntax:
import mx.events.EventDispatcher.*;
But Im getting this error message:
**Error** Scene=Scene 1, layer=Layer 3, frame=1:Line 1: Syntax error.
import mx.events.EventDispatcher.*;
Total ActionScript Errors: 1 Reported Errors: 1
And Im using AS 2.0...any answers? Thanks...
Problem Creating Classes / Xml Import
I am trying to create a class. In a small test I cannnot succeed in creating an instance of my newly created class, and import some XML data into it.
I can import xml data into a prototype, but some how the instance does not get this info.
Can anyone help me with a suggestion?
I have a zip with the testfiles (fla, .as and xml): http://www.flashfocus.nl/forum/attachment.php?attachmentid=5646
Thanks in advance for the help,
List Of Import Classes And Descriptions
OK, we just got CS3 installed at work, and we're starting to learn the new AS3. So far we love it... but we want to know ALL the import classes and descriptions of what they are. is there a list anywhere? I've searched the help, searched the web, can't seem to find anything.
something like:
flash.events. // used for blah blah blah
flash.events.x // blah blah blah
is there any list like this?
Import Classes Syntax Problem
I'm trying to import a class and all the classes in that directory. Here is my syntax:
import mx.events.EventDispatcher.*;
But Im getting this error message:
**Error** Scene=Scene 1, layer=Layer 3, frame=1:Line 1: Syntax error.
import mx.events.EventDispatcher.*;
Total ActionScript Errors: 1 Reported Errors: 1
And Im using AS 2.0...any answers? Thanks...
Does Flash Import Unused Classes?
Like a lot of you I have a growing library of custom components and util classes. Now what I'm wondering is if I use a class which imports a number of other classes(an obvious one would be a custom tweening util class importing Robert Penner’s AS2.0 classes), and some of these imported classes are never used in the published file, are they still added to the published movie increasing its file size? If so WHY?!
Sorry if this has been asked before! I did do a search first.
Include Or Import Other Classes Inside Of Another Class?
I'm creating a component and a class for that component using the new 2.0 OOP methods. I need to use the Robert Penner movieclip Tween class calls with in my class, which means I have to import or include that class in order the use it. But I can't seem to find a way to do it. Both include and import return errors, stating that that it is not allowed within a class definition. Is this just not possible? Any help?
I Need To Import Only Needed Classes Into My Mother Class
If anyone has any idea how to perform a dynamic #include workaround or dynamic import. What i have is a class that needs the code from other classes to perform some operations and what I want is to be able to import only the classes i need based on a parameter. Thanks in advance if some replyes to this
Selecting The Classes/packages To Import At Runtime
Before starting an class or code, you should put all your import statements..
Now I have flash application, which offers a search feature which relies on some pretty huge classes. The user is unlikely to use this feature. However, importing those classes anyway adds some pretty large kbs to my application. Is there a way to import these classes at runtime ONLY IF the user chooses to use this feature?
Thanks
Import MovieClips/Classes From External File
Hey All,
I'm working on an OOP/Class based application. In order to save on filesize, I have some of my assets in another swf file, with their linkage properties set to classes that give them properties and actions:
Class: src.BLNavStation_Circle
Base class: flash.display.MovieClip
How Do I "import" The Classes?
Hi guys...I'm giving Lee Brimelows "cube" paper vision tut a go...seems all pretty straight forward as always he is clear and step by step...however he brushes over the very start about how to ge the paper vision stuff into flash....I cant find my "snippets" window in flash!!!!!
I have followed the other threads on here and have all the classes in a folder called greatwhite......
Now what?????
Slightly confused!!
Custom Classes: One Class Tracks Multiple Other Classes?
I'm working on a coloring that allows kids to place objects on a scene and then color them so the image can be printed out. So assume you have sky background, the child can select a bird object, drag it into place and once they have it in place, color everything on the page (with a given palette of colors.)
So far it going great. However I want to track what objects have been added to the drawing on the fly. I have a potential solution using arrays but I'm thinking this is perfect opportunity to start using custom classes.
I'm thinking that I'd create a new instantiate a copy of the object class each time an object is added to the scene. However to track the objects added to the scene I'm thinking I'll also use an listing class to track them.
What I'm not sure about is the would the listing class simply contain an array of object identifiers? Any thoughts on the structure of the listing class?
I'm very new to oop as I've mainly been doing procedural programming up to this point but I'm eager to give this a shot.
Thanks!
Bulk Import Statments Vs. Specific Import Statements...any Performance Difference?
Lets say I have 20 classes located at nl/amsterdam/simulation/model/. Now I'm writing another class that is going to use some of those 20 classes. Is there any performance difference in the compiled swf if I import them all using a wildcard:
Code:
package nl.amsterdam.simulation.view
{
import nl.amsterdam.simulation.*
...
versus importing each specific one that I need?:
Code:
package nl.amsterdam.simulation.view
{
import nl.amsterdam.simulation.model.Tulip;
import nl.amsterdam.simulation.model.Canal;
import nl.amsterdam.simulation.model.Prostitute;
import nl.amsterdam.simulation.model.StonedTourist;
import nl.amsterdam.simulation.model.BuisnessMan;
import nl.amsterdam.simulation.model.Windmill;
import nl.amsterdam.simulation.model.CoffeeShop;
import nl.amsterdam.simulation.model.SkinnyBuilding;
...
Or is there only a difference in the time it takes to compile, not the time it takes to execute?
Using Flex Classes In Classes Linked To Symbols
Hi all
I have a fla file where I link a symbol to an action script class. This action script classes references mx.collections.ArrayCollection; so when I attempt to publish the fla file, I get the error message:
1017: The definition of base class ArrayCollection was not found.
I then tried to add a class path (this folder contains the mx... classes):
C:Program FilesAdobeFlex Builder 3sdks3.0.0frameworksprojectsframeworksrc
and the the above error 1017 wasresolved, but now I get the error:
Version.as, line 18 1004: Namespace was not found or is not a compile-time constant.
So now I am pretty much stuck. What do I need to do for this to work ? Please note that the code compiles fine in flex, so it is not som basic coding error ?
Instantiating Classes Inside Classes
I have a class called spaceship in which i have instanciated another class weapon. However, when i call on a method of weapon (which at this point is just simply trying to trace "hello"), it doenst work and the object basically doenst exist. It's delcared in the class as:
Code:
private var ShipWeapon:weapon;
Note that when I instantiate a weapon class on the main timeline the thing works and "hello" is printed to the output panel. However, nothing at all happens when instantiated the weapon class inside my spaceship class. Both traces come up "undefined". Do i need to declare the class as some sore of special class or somethings? Thanks in advance
[classes] Best Method To Communicate Between Classes
Here's the scenerio:
I have a component that is associated with a class. Inside the component is an empty movieclip.
-component (part of a class)
-mc
The main component's class upon init will load a movie from a remote server into the mc movieclip. System.security.allowDomain is in there...
Now, inside the swf that gets loaded into the mc is an empty movieclip that's associated with it's own class:
-component (part of a class)
-mc (contains loaded movie)
-mc (part of a separate class)
Now here's the challenge... I need to have the loaded movie > mc's class be able to communicate with the main component's class.
What's the best setup to be able to communicate between the two classes directly? That is, if I don't have loaded movie > mc > class inherit from the component's class.
thanks in advance...
Nathan
Best Flash Classes (Taught Classes)
I think this site is great for newbies in the flash world to Advanced flash developers. I am an intermediate flash designer/developer and I have been using flash since 1998. My strengths are more on the design side for sure. I am just curious what your experience is with going to a week long flash class. I have been to several classes and my last one was a week long one with Joshua Davis on advanced actionscript in NYC a while back. This was still coding in AS1 with dot syntax so only some of it is relevant to what we are doing today. I am wondering what are the best classes out there today and what your experiences are if you have been to any. I wish another event like this: grant skinners FITC flash 8 workshop or this Colin Moocks actionscript bootcamp were available but I can't find anything like it. My friend went to Colin's workshop a while back and mentioned how he went into design patterns with AS2 and it would be great to learn about that. ANyhow any suggestions would be great. Post your thoughts.
Instantiating Classes Inside Classes
I have a class called spaceship in which i have instanciated another class weapon. However, when i call on a method of weapon (which at this point is just simply trying to trace "hello"), it doenst work. The compiler obviously didn't flag anything, but i also get "undefined" for all my weapon class varibles. Do i need to declare the class as some sore of special class or somethings? Thanks in advance
Can't Import Import Fl.controls.ComboBox
Hi all!
I am starting learning AS 3.0 (used to use AS 2, that was sweet times ) and actually can't understand simple thing - why I can't include that package from action script?
I actually start new Action Script 3 file, and put single line in first frame
Code:
import fl.controls.ComboBox
and got errors
Code:
1172: Definition fl.controls:ComboBox could not be found.
1172: Definition fl.controls:ComboBox could not be found.
Actually thats part from the code listed at the manual and I don't have any idea, why it doesn't work.
Also when I open components window and drag combobox to scene error is not showed any more.
Any ideas how can I solve this problem without adding combobox to the library?
[Flash 8] Import, Import, Import
Last edited by Nutrox : 2005-09-18 at 06:24.
Ahh!! I'm already getting a bit tired of having to continuously import classes into Flash for things like BitmapData, Rectangle, and Point etc. Is there a way I can set things up so that these classes don't need to be manually imported all of the time?
I've tried a few things including : (a) Creating extension classes, but Flash moans about class paths when I try to import something like flash.display.BitmapData into my own class. (b) Setting a class path so that it points at the class directory .. $(LocalData)/Classes/FP8/flash/display/ .. but that doesn't work either (I know why, but it was worth a shot). (c) Importing the entire class package .. import FP8.* .. but that causes errors with a tonne of other classes. import FP8.geom.* etc works though, but that doesn't really help.
Am I just missing something obvious here, or is there no way around this?
Si ++
Accessing Classes From Classes
ok something I don't get. In as2 I used to have a main class, which I created an instance of my Useful.as Class in. And then when I created say a monster instance from my monster class, I used to pass it a reference to the main class, so I could access the Useful instance from a function in my monster class like this
Code:
main.Useful.RandomNumber(1,100);
But this doesn't seem to work in as3
It just gives me a reference error, even though when you look with debug mode the Useful instance is sitting there in the main class, and there is also a reference inside my monster instance to the main class. I found that if a pass a direct reference to the Useful instance to the monsters constructor, and setup a var called Useful inside my monster instance then I can just do this
Code:
Useful.RandomNumber(1,100);
but why doesn't the old AS2 way of things work?
Accessing Classes From Other Classes
Two Classes: Tile, Map
I know Tile works and is accessible from the main timeline because I can create and object and trace properties, so the timeline is able to import it.
When placing the same import statement in the Map class I get: 1046: Type was not found or was not a compile-time constant: Tile.
Here is code
ActionScript Code:
package layout
{
public class Tile
{
public var filename:String;
public var myX:int;
public var myY:int;
public var ext:String;
public function Tile(sFilename:String)
{
filename = sFilename;
var nPos1 = sFilename.indexOf('_');
var nPos2 = sFilename.indexOf('.');
myX = Number(sFilename.substring(0, nPos1));
myY = Number(sFilename.substring(nPos1+1, nPos2));
ext = sFilename.substring(nPos2, sFilename.length);
}
}
}
ActionScript Code:
package layout
{
import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
import layout.Tile;
public class Map extends Sprite
{
// tiles[y][x]
public var tiles:Array = new Array();
public function Map()
{
if (map == false)
{
var map:Sprite = new Sprite();
this.addChild(map);
}
}
public function AddTile(sFilename:String)
{
var Tile:Tile = new Tile(sFilename); //This line causes issue
tiles[Tile.myY] = new Array();
tiles[Tile.myY][Tile.myX] = new Array(Tile, false);
}
}
}
Using Classes Inside Of Classes
I have created a custom sound class called MySoundClass that extends the Sound class... it is declared as class com.stickyMatters.WineGlassPiano.MySoundClass. I also have another class called SongPlayer that is declared as com.stickyMatters.WineGlassPaino.SongPlayer... my question is.. how do i use the MySoundClass inside of the SongPlayer class... when I try to import it says I cannot use the import statement inside of a class file. I know in AS3 you can use the package keyword to create packages and do that... but as far as I can see there is no package keyword in AS2... because I tried, and it just tells me htere is a syntax error on the line with the package declaration... can you use one custom class inside another? and if so... how?
P.S. just to be sure... i am using flash CS3 and writing AS2 files. Thanks!
Classes In Mx 2004 (new To Classes)
hi everyone, Im Nubis, from Argentina.
I´m new to woking whit classes, Im using flash mx 2004 pro.
Ive created a class, that works correctly, it creates a square, a textbox, and uses a variable to pupulate the textbox.
(im sorry for my english)
in my library i have a MC (an empty MC) that is linked to that class.
I use this script to place the clip on the stage
attachMovie("card", "card", 1)
iknow the class works fine, but, I dont know where to pass the parameters to the class.
And if I use : Card = new MyCard("this Card´s Name or label ")
both the clip and the textbox are not created.
could anybody please help me?
thanks in advance :)
(feel free to make comments about my code)
this is my class code:
// MyCard
class MyCard extends MovieClip {
var thisCardName:String;
//method for creating the square
function gen_sqr (){
this.createEmptyMovieClip("Square",2);
with(this["Square"]){
beginFill (0x0099FF, 100);
lineStyle (1, 0x003399, 100);
moveTo (0, 0);
lineTo (100, 0);
lineTo (100, 70);
lineTo (0, 70);
lineTo (0, 0);
endFill();
}
}
//method for generating the textfield
function gen_txt(my_text){
this.createTextField("mytext",3,0,0,50,20);
with(this["mytext"]){
text = my_text;
multiline = true;
html = true;
}
}
//constructor
function MyCard (thisName:String){
//set the name or label for the card
thisCardName = thisName;
//
gen_sqr()
gen_txt(thisName)
//
trace("newclass Created")
trace(thisCardName)
}
}
Importing Classes In To AS3 Classes?
I am not sure how to import multiple classes into an AS3 class. Also I am bit confused on how "package" works now.
This is currently what I have and its wrong:
Code:
package {
import flash.display.*;
import flash.net.URLRequest;
import flash.events.Event;
class LoadImage {
public function LoadImage() {
var container:Sprite = new Sprite();
addChild(container);
var pictLdr:Loader = new Loader();
var pictURL:String = "catfishSMv.jpg"
var pictURLReq:URLRequest = new URLRequest(pictURL);
pictLdr.load(pictURLReq);
pictLdr.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
function imgLoaded(e:Event):void {
container.addChild(pictLdr.content);
}
}
}
}
How should I actually do this?
Thanks
Classes In Mx 2004 (new To Classes)
hi everyone, Im Nubis, from Argentina.
I´m new to woking whit classes, Im using flash mx 2004 pro.
Ive created a class, that works correctly, it creates a square, a textbox, and uses a variable to pupulate the textbox.
(im sorry for my english)
in my library i have a MC (an empty MC) that is linked to that class.
I use this script to place the clip on the stage
attachMovie("card", "card", 1)
iknow the class works fine, but, I dont know where to pass the parameters to the class.
And if I use : Card = new MyCard("this Card´s Name or label ")
both the clip and the textbox are not created.
could anybody please help me?
thanks in advance :)
(feel free to make comments about my code)
this is my class code:
// MyCard
class MyCard extends MovieClip {
var thisCardName:String;
//method for creating the square
function gen_sqr (){
this.createEmptyMovieClip("Square",2);
with(this["Square"]){
beginFill (0x0099FF, 100);
lineStyle (1, 0x003399, 100);
moveTo (0, 0);
lineTo (100, 0);
lineTo (100, 70);
lineTo (0, 70);
lineTo (0, 0);
endFill();
}
}
//method for generating the textfield
function gen_txt(my_text){
this.createTextField("mytext",3,0,0,50,20);
with(this["mytext"]){
text = my_text;
multiline = true;
html = true;
}
}
//constructor
function MyCard (thisName:String){
//set the name or label for the card
thisCardName = thisName;
//
gen_sqr()
gen_txt(thisName)
//
trace("newclass Created")
trace(thisCardName)
}
}
Accessing Classes From Classes
Hi... I'm having some trouble with these bits of code... I got some help before from wangbar to sort it out when the var stored was in a class of its own. But trying to access it from another class isn't working...
class Ipa{
var c : Settings;
function Ipa() {
}
}
class Settings {
var currSubs:Boolean;
function Settings (s:Boolean) {
currSubs = s;
}
function getSubsOn ():Boolean {
return currSubs;
}
function setSubsOn (s:Boolean):Boolean {
currSubs = s;
return currSubs;
}
}
then at root level:
var dpp : Ipa = new Ipa();
dpp.c.setSubtitlesOn(false);
and level 3:
_global.subtitles = _level0.dpp.c.getSubtitlesOn();
if ( _global.subtitles == false){
_level3.speech._visible = false;
};
And nothing happens...subtitles still showing...
Thanks in advance for help.
silverswim
AS1 Classes And AS2 Intrinsic Classes
Anyone ever mess around with writing an AS1 style class (so that it can be used prior to your class export frame) and writing an intrinsic AS2 class to go along with it, to enable compile-time checking?
It's working well, at least for instance members. (The trick is you need to define your constructor like so:Code:
var MyAS1Class = function... and NOTCode:
function MyAS1Class...)
But for static members, I can't seem to get the compiler to recognize the AS1 static members as validating against the AS2 intrinsic classes static members. In other words:
Code:
import the.intrinsic.class.Foo
#include "the/actual/as1/class/Foo.as"
var myFoo:Foo = new Foo();
// This cause the compiler to complain:
myFoo.nonExistentProperty = "moo";
// This goes by undetected:
Foo.NON_EXISTENT_STATIC_PROP = "moo";
// This gets caught:
the.intrinsic.class.Foo.NON_EXISTENT_STATIC_PROP = "moo";
// But doesn't help because it's referencing the intrinsic class, which
// doesn't actually have any code and never gets compiled
(obviously the properties mentioned are not defined in this example intrinsic class)
It's apparently a problem of the actual AS1 class being a var on the timeline and the AS2 intrinsic class existing in a different namespace.
I've tried putting my AS1 class in the _global.the.intrinsic.class.Foo variable, like it would if it were a regular AS2 class.
I've tried Object.registerClass("_global.the.intrinsic.class.Foo", Foo), which I thought would work, but maybe I'm doing it wrong.
So far the best workaround is this:
Code:
Foo.__resolve = function(name:String):Void {
trace("Oops, the member you've accessed, " + name + ", does not exist");
}Which at least provides run-time checking, but not compile-time checking, which is obviously why I'm doing this intrinsic thing at all.
I know this is a very esoteric question...any suggestions?
PS
Man, I do NOT miss writing AS1 OOP! I tend to forget how great AS2 OOP is when I use it exclusively. But coming back to AS1 OOP...<napoleonDynamite>Gawh!</napoleonDynamite>
Using Custom Classes Inside Of Custom Classes
I have created a custom sound class called MySoundClass that extends the Sound class... it is declared as class com.stickyMatters.WineGlassPiano.MySoundClass. I also have another class called SongPlayer that is declared as com.stickyMatters.WineGlassPaino.SongPlayer... my question is.. how do i use the MySoundClass inside of the SongPlayer class... when I try to import it says I cannot use the import statement inside of a class file. I know in AS3 you can use the package keyword to create packages and do that... but as far as I can see there is no package keyword in AS2... because I tried, and it just tells me htere is a syntax error on the line with the package declaration... can you use one custom class inside another? and if so... how?
P.S. just to be sure... i am using flash CS3 and writing AS2 files. Thanks!
Using Custom Classes Inside Of Custom Classes
I have created a custom sound class called MySoundClass that extends the Sound class... it is declared as class com.stickyMatters.WineGlassPiano.MySoundClass. I also have another class called SongPlayer that is declared as com.stickyMatters.WineGlassPaino.SongPlayer... my question is.. how do i use the MySoundClass inside of the SongPlayer class... when I try to import it says I cannot use the import statement inside of a class file. I know in AS3 you can use the package keyword to create packages and do that... but as far as I can see there is no package keyword in AS2... because I tried, and it just tells me htere is a syntax error on the line with the package declaration... can you use one custom class inside another? and if so... how?
P.S. just to be sure... i am using flash CS3 and writing AS2 files. Thanks!
Import Via "import To Stage"
I opened a new AS2 document in Flash CS3
I designed a clip which I saved as an fla and exported to an swf file.
Now I imported the swf onto the stage but all that has happened is that the seperate swf componens are on the stage and not the complete clip?
Classes
I'm having trouble finding info on how to setup classes in flash 5.
What i want to do is:
Create balls at a set interval.
These balls roll back and forth across a floor changing direction and color when they bounce off the walls.
So I'd like each ball to have a color variable and a direction variable.
How do i make a movieclip with these 'internal' variables, and how do i create them during play?
Using 3D Classes In MX
Hi,
I am hoping someone here is familiar with Brandon Williams 3D classes for creating cameras and vector objects in 3D in Flash MX.
I am trying to create a continous flyaround of a circular set of movieclips. This works fine if I rotate the movieclips using the rotation matrix, but to give me more interaction I wanted to create a camera that flew around the static movieclips. To do this I tell the camera to move sideways by a set amount and then look at a triplet point (the center of the circle of movieclips - and this is fine in the y direction, but then I wanted to add a more interesting movement upwards as well, so I tell the camera to move_upwards by a set amount and then look at the triplet. This works for 90 degrees of rotation at which point I can't tell exactly what it is doing but seems to have a problem deciding which direction to go and so just sits there.
If anyone can understand what I am going on about - help me!!
Robin
Classes?
How can i define a class like the Array class where you can assign values to a variatble directly and yet have it have functions attached to it.
I want to be able to do this.
myVar = 5;
myVar.testOutput();
//-----I want output to be
5
is this possible?
thanks
|