Netconnection In Document Class?
can you only make the netconnection in the document class? Everytime I try to make one in a class that isnt the document class I get errors. I would assume you can make them in any class am I doing something wrong? thank you!
ActionScript.org Forums > Supporting Technologies > Flash Media Server
Posted on: 09-14-2008, 03:03 AM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
NetConnection Error In Separate Class
I get this error:
Code:
ArgumentError: Error #2126: NetConnection object must be connected.
at flash.net::NetStream/construct()
at flash.net::NetStream()
at com.ourmedia.utilities::GetFrame$cinit()
at global$init()
at OMPlayer_fla::MainTimeline/frame1()
Error #2044: Unhandled AsyncErrorEvent:. text=Error #2095: flash.net.NetStream was unable to invoke callback onMetaData. error=ReferenceError: Error #1069: Property onMetaData not found on flash.net.NetStream and there is no default value.
at vidPlayer_fla::MainTimeline/frame1()
when I have this call in my main player file:
Code:
GetFrame.myFrame(finalUrl);
Which refers to this file - which seems like a complete enough function to me to not generate an error:
Code:
package com.ourmedia.utilities {
import flash.media.*;
import flash.net.*;
public class GetFrame {
public static var theString:String;
public static var connected:NetConnection = new NetConnection();
public static var nStrm:NetStream = new NetStream(connected);
public static var video4frame:Video = new Video();
public static var BUFFER_TIME:Number = 8;
public static function myFrame(theString){
connected.connect(null);
video4frame.attachNetStream(nStrm);
//video_mc.addChild(video);
nStrm.play(theString);
nStrm.pause();
}
}
}
anybody get this one before?
Am I not able to create a connection in a package - independent of the net connection I'm using for playing the main video?
Overall I know creating video playback functions in AS3 pretty well I think, but I'm trying to get into separating some functions into packages, and this seems to be a bad start.
Pass Class Object To FMS Using NetConnection.call Method
Hello All,
I have a custom class that defines several methods on itself to retrieve its data. This class object is then sent to FMS via the NetConnection.call method. Once received by FMS, FMS calls the remote method to dispaly the class object on connected clients (minus the originator).
Now, standard properties are displayed correctly, but when I call the class method to retrieve the class data, no data is retrieved.
My question is, can FMS handle class objects as parameters in a NetConnection call. If not, is there a better practice of applying methods to retrieve the class data? Example below...
class com.QuizItem
{
var numOfAnswers;
var getAnswer;
function QuizItem(question)
{
this.numOfAnswers = 0;//<-- Returns correct number of answers
this.getAnswer = function(answerNumberToGet)//<-- Does not return any data when called by client side script
{
return this.answers[answerNumberToGet];//Already populated array
}
}
}
Regards,
Shack
AddChild Works With Document Class, But Not Timeline-instantiated Class
I cannot get a sprite to display for me when I create an instance of a very simple class in my FLA file's timeline.
However, when I make the class file the FLA's document class file, it displays just fine.
The task in question is simply drawing a square with the shape class.
Problem example:
My class, Test.as, resides in the same folder as my FLA file - so I don't use any import statement. I'm new to lots of CS3 stuff. Can anyone tell me why this doesn't work and create the shape on the stage? This seems to fail silently without any errors:
var myTest:Test = new Test();
Working example:
Setting the document class to Test.
Attach Code
// Test class
package {
import flash.display.*;
public class Test extends Sprite {
public function Test():void{
doThing();
}
private function doThing():void{
var myRect:Shape = new Shape();
myRect.graphics.lineStyle (2, 0xcc0000, 1);
myRect.graphics.beginFill(0xcccccc, 1);
myRect.graphics.drawRect(10, 10, 200, 200);
addChild(myRect);
}
}
}
Document Class Initialising Another Class With Display Objects
Hi
I'm currently learning AS3 and have got stuck with something fundamental to do with Flash and the Document Class.
I have a very simple Document Class as follows:
package {
import flash.display.*;
import com.Application;
public class EntryPoint extends Sprite {
public function EntryPoint() {
var app:Application = new Application();}}
}
I then would like to build out into other classes/patterns and want the following code to simply attach an item from the library on to the stage.
The item in the library has a Class reference of CircleTest and has a Base Class of flash.display.Sprite.
My Application class is as follows:
package com {
import flash.display.*;
public class Application extends Sprite{
public function Application() {
var mc_root:Sprite = new Sprite();
addChild(mc_root);
var circleTest:CircleTest = new CircleTest();
mc_root.addChild(circleTest);}}
}
When I compile this from Flash I get nothing other than an empty stage :-(
Please can someone tell me what I'm doing wrong here.
Many thanks in advance
D
How Do I Access A Variable Declared In My Document Class From Another Class
Hi there,
I'm pretty new to classes and am probably missing something really basic so apologies if this seems like a stupid question.
I'm trying to access a variable that I've declared in my document class from within another class.
I know I can pass the variable through when I call the class as follows:
Code:
var myBall:Ball = new Ball(5);
and pick this up in the Ball function within my Ball class as follows:
Code:
public function Ball(ballSpeed) {
trace(ballSpeed);
}
But what if I don't want to do that as I have a whole load of general global variables I want to access which were defined in my document class?
What I actually want to do is just have access to all the variables defined in the document class from within the Ball class.
I tried parent.variableName and various other ways of accessing what I need but all of them spit back errors.
Any help would be really appreciated - I'm sure this is very basic but I'm totally stuck on this.
Many thanks.
Ian
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.
Call Function Of Document Class From MovieClip Class
How can I run a function of the main document class from a class of a MovieClip? I usually just used MovieClip(parent).function(), but now my MovieClip has another parent. Or what do I have to pass to the MovieClip class when creating the MovieClip to acess the main document class?
Sharing Vars Between Document Class And An Imported Class.
I'm working on my first really in depth AS3 project, learning as I go.
I've been sorting through the XML docs and i've bumped my head into a bit of a question. So, to preface, I have been able to load the XML successfully, but I want to be able to use my own XML loader class to load the XML and then be able to reference it from the document class. Also, I'd like to be able to send a file path to the loader class when I call it.
Not sure if that makes sense, but I will post what I did and see how bad it is
The document class:
ActionScript Code:
package rg.sites{
// flash classes
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.*;
import flash.display.Graphics;
import flash.display.Shape;
import flash.text.*;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.net.*;
import flash.errors.*;
// RG classes
import rg.classes.XMLSiteLoader;
// Layout Objects
public class SiteCurrent extends MovieClip {
// vars
public var siteLoader:XMLSiteLoader;
public var site_xml:XML;
public var xml_site_loading:String = "current_site.xml";
public function SiteCurrent() {
trace("Site Current is loaded");
siteLoader = new XMLSiteLoader();
siteLoader.addEventListener(Event.COMPLETE, xmlSiteLoaded);
}//end constructor function
private function xmlSiteLoaded(event:Event):void {
trace(site_xml.toXMLString());
trace("
" + "Background art: " + site_xml.section.(@id == "Splash"));
}
}//end class
}//end package
The XMLSiteLoader class:
ActionScript Code:
package rg.classes
//
// XMLSiteLoader version 0.1 beta
//
{
//import fl.controls.*;
import flash.net.*;
import flash.events.*;
import flash.errors.*;
public class XMLSiteLoader extends EventDispatcher {
//public var site_xml:XML;
private var siteReq:URLRequest;
private var siteLoader:URLLoader = new URLLoader();
public var site_xml:XML;
public var xml_to_load:String;
public function XMLSiteLoader() {
//trace(stage.xml_site_loading);
if(xml_to_load == true) {
trace("xml file path sent");
siteReq = new URLRequest(xml_to_load);
}
else {
trace("No XML file path sent, use default value");
siteReq = new URLRequest("current_site.xml");
}
trace("XML Site Loader is loading: " + siteReq);
siteLoader.load(siteReq);
siteLoader.addEventListener(Event.COMPLETE, xmlLoaded);
} // constructor class
private function xmlLoaded(event:Event):void {
site_xml = new XML(siteLoader.data);
trace("
" + "from XML Site Loader: " + site_xml.section.(@id == "Splash"));
dispatchEvent(new Event(Event.COMPLETE));
}
}//end class
}//end package
I get an error that says:
Quote:
Site Current is loaded
No XML file path sent, use default value
XML Site Loader is loading: [object URLRequest]
from XML Site Loader: portfolios/splash_gallery/splash.xml
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at rg.sites::SiteCurrent/xmlSiteLoaded()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at rg.classes::XMLSiteLoader/xmlLoaded()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
Thanks in advance for any thoughts or suggestions.
-g
Displaying A TextField From A Class That Is Called From My Document Class
I'm having a problem with my main project so I've made a small test project to replicate it. The code's included here.
I've created a new .fla called TextboxFromClass.fla that's empty except for a linked in Document class called TextboxFromClass.as
I've created another class called TextboxClass.as
Everything's linked and referenced properly - when I run it there's no errors and I get a trace output "Got here" but only the TextField for the Document Class displays ("From the Doc Class"), not the one from the TextboxClass ("From the TextBoxClass Class").
I'm guessing it's a scope thing but I'm fairly new to ActionScript 3.0 so I'd appreciate your help.
Attach Code
//Code in the Document Class (called TextboxFromClass.as
package script
{
import script.*
import flash.display.MovieClip;
import flash.text.*;
public class TextboxFromClass extends MovieClip
{
var inputNameLabel:TextField = new TextField();
var backgroundGreen : int = 0x2E510B;
var foregroundGreen : int = 0x00FF99;
public function TextboxFromClass()
{
with (inputNameLabel)
{
x = 300;
y = 200;
width = 200;
height = 30;
text = "From the Doc Class";
}
var format:TextFormat = new TextFormat();
with (format)
{
font = "Arial";
color = foregroundGreen;
size = 20;
}
inputNameLabel.setTextFormat(format);
addChild(inputNameLabel);
//This should output some text like the above - but doesn't
var abc:TextboxClass = new TextboxClass();
}
}
}
// Code in TextboxClass.as
package script{
import script.*;
import flash.display.MovieClip;
import flash.text.*;
public class TextboxClass extends MovieClip {
var t:TextField = new TextField();
var backgroundGreen : int = 0x2E510B;
var foregroundGreen : int = 0x00FF99;
public function TextboxClass() {
with (t) {
x = 300;
y = 250;
width = 300;
height = 30;
text = "From the TextBoxClass Class";
}
var format:TextFormat = new TextFormat();
with (format) {
font = "Arial";
color = foregroundGreen;
size = 20;
}
t.setTextFormat(format);
addChild(t);
trace("Got here");
}
}
}
Edited: 02/09/2008 at 07:42:24 AM by SoCentral2
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.
Button Class Affect The Document Class
I want it so when you click the button, it can make the movie go to the next scene or change a variable in the document class. I can do it on the timeline but I want it as a class instead
And it would be cool if I could figure out how to make seperate packages just for functions and variables so I didn't have to write it all in one document, I just don't want to code in a big pile after I heard you can do this
Cheers
When Should I Use Document Class And External Class Files?
Hello all,
I was recently sent on an intensive three day Actionscript 3 course by my employers - it was fantastic and gave me a great understanding of the fundamentals of coding with Actionscript.
I have one question that I wasn't really able to raise during training, the topic was touched on briefly but wasn't explained in any detail.
When should I use document class files and external class files? If I understand it correctly, creating Linkage with an element in my library then creates a class file, and that file should contain specific functionality relating to the element. For instance, if it was a movie clip in my library that is used to contain loaded product images, then the associated external class file should contain the code that handles the URLRequest and the Loader, plus any extra functionality such as Event Listeners and a function for dragging and dropping of the MC. When I want to access that functionality, I call the function in my class file from my main movie and pass it the correct parameters. Am I on the right track here?
When should I use the document class? I know how to set a document class, and going by my previous logic, I imagine it's used to contain global functions that may be required (such as exiting the movie, file handling etc). Am I correct?
One more - say I'm using an external class file - do I need to import it on the first frame of the actions layer, or can I import in my document class?
That's it, a little clarification need really.
Thanks in advance.
Problems With Document Class Interacting With Another Class
Here is my problem:
I need to have a menu on the bottom of the screen to have mouse overs / on / off states. When the user mouses over a button I need to have the slide name change in the text field on the Stage, when they mouse off, the Slide name of the button with the on state should be displayed. When the click on it, a slide should load.
I have a Movie Clip with a linkage ID: Nav Button in the library that has timeline animations with labels: over, on, off, and passed and onBut that makes the button change states.
I have a Document Class(Presentation.as) that creates instances of the external class NavButton class (NavButton.as) with the values it received from XML.
When user mouse overs a button I need a text in the textField that is created from the Document class to change value. but I can't access that text field from the NavButton class.
code from Document Class: Presentation.as
public var pageTitle:TextField = new TextField();
pageTitle.x = 500;
pageTitle.y = 500;
if (sStatus == "on"){
pageTitle.text = sTitle; // works! sTitle comes from XML
}
addChild(pageTitle);
code from NavButton.as
public function onButtonOver(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay("over");
////NOT WORKING, need to assign this text value to the text field on stage!
stage.pageTitle.text = this._btnTitle;
}
public function onButtonClick(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay("on");
////NOT WORKING, need to call this function in document class
createSlide();
}
Also, once the user click on the button I need another slide to load so I need to call a function in the document class to start loading that data from XML.
So I am having few problems, for about 5 days already. Let's say my hair is in place but I really really want to know how to do it.
1). How to assign values from the mouseover function of the NavButton class, to the textField that was created in the Document class? So that it changes when u mouse over and goes back to the default value when it's off.
2). How to call a function in the Document class from the mouseClick function of the NavButton class, to start building out the rest of the info.
I tried having a textField placed manually on stage with a different name, but still I can't access it from the NavButton class!
My code is attached.
Thank you very much for your help!
-D.
How Do I Call A Method Of The Document Class From Another Class?
I am creating instances of another class from inside my document class. I want these instances to communicate with the document class, how is this accomplished in AS3?
For example, the document class creates a series of boxes with something like:
var box = new Box();
The document class can now call methods of box with box.method(). The question is how can box call methods within the document class?
Reading Document Class Variable From A Class
I have a document class that establishes a variable called "_captioning". The document class then loads a button class that on attachChild needs to check to see if _captioning is set to true or false. I can load this class and can trace strings being generated inside the class but I can't target the _captioning variable outside of it in the document class.
I just need to see how I can get this button class to read things in the document class.
Accessing Document Class From Static Class?
I am building a family tree like tree in flash.
I have a package TreeManager which holds all my classes.
The document class TreeManaager.Tree controls adding new nodes to the stage.
ActionScript Code:
public function addProfile(relationship:Object):void
{
profile = new Profile();// create new profile
var align:Alignment = new Alignment();//make Alignment object
...
The profile class controls all the internal node functionality.
Question - If I have a button in my node MC (profile class) which should add a new relationship (i.e. call addProfile) how to I do this?
ActionScript Code:
public class Profile extends MovieClip {
public function Profile ():cool:
{
this.addEventListener(MouseEvent.CLICK,Tree.addProfile);
This always throws an error. I can just add the buttons events from the document class, but it would be helpful to know if you can access the document class from a packaged static class?
ActionScript Code:
// add button events
profile.mother.addEventListener(MouseEvent.CLICK,addRelationship);
profile.brother.addEventListener(MouseEvent.CLICK,addRelationship);
profile.son.addEventListener(MouseEvent.CLICK,addRelationship);
AddChild From Class Called From Document Class
Hey all,
I've recently found the disadvantages of adding code to the timeline and the great and beautiful advantages of moving them to the document class and using external classes to hold my code, so areas of this i'm quite new with this still.
Im having a bit of trouble with adding a MovieClip from the library to the stage from a class which is called from the document class.
The document class imports the new class and creates the instance, this is all fine as i can see the trace statement from the second class.
The following code below works when in the document class... which it should do and is the way i've always used to add a child to the stage
ActionScript Code:
// imports etc + code below wrapped in constructor
var testInstance:Visual_Scale3 = new Visual_Scale3();
addChild(testInstance);
But if i was to use the same code in the second class called from the document class nothing happens, here is my second class
ActionScript Code:
package uk.co.website.scale
{
import flash.display.Sprite;
import Visual_Scale3;
public class Scale3 extends Sprite
{
public function Scale3() {
trace("Scale3 class loaded!");
var testInstance:Visual_Scale3 = new Visual_Scale3();
addChild(testInstance);
}
}
}
All i see is the trace statement "Scale3 class loaded!", im guessing its something to do with not being able to locate the MovieClip, Visual_Scale3 from the timeline.
Thanks in advanced,
alex
Problems With Document Class Interacting With Another Class
Here it goes:
So i need to have a menu on the bottom of the screen to have mouse overs / on / off states. When the user mouses over a button I need to have the slide name change in the text field on the Stage, when they mouse off, the Slide name of the button with the on state should be displayed.
So I have a Movie Clip in the library that has timeline animations with labels: over, on, off, and passed and onBut that makes the button change states accordingly.
I have a Document Class(Presentation.as) that creates instances of the another class NavButton class (NavButton.as) with the values it received from XML.
When user mouse overs a button I need a text in the textField that is created from the Document class to change value. but I can't access that text field from the NavButton class.
-----------------code from Document Class: Presentation.as
public var pageTitle:TextField = new TextField();
pageTitle.x = 500;
pageTitle.y = 500;
if (sStatus == "on"){
pageTitle.text = sTitle;
}
addChild(pageTitle);
-----------------code from NavButton.as
public function onButtonOver(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay("over");
////NOT WORKING, need to assign this text value to the text field on stage!
stage.pageTitle.text = this._btnTitle;
}
Also, once the user click on the button I need another slide to load so I need to call a function in the document class to start loading that data from XML.
public function onButtonClick(e:MouseEvent):void
{
e.currentTarget.gotoAndPlay("on");
trace(this._btnId);
////NOT WORKING, need to call this function in document classto create a slide
createSlide();
}
So I am having few problems, for about 5 days already. Let's say my hair is in place but I really really want to know how to do it.
1). How to assign values from the mouseover function of the NavButton class, to the textField that was created in the Document class? So that it changes when u mouse over and goes back to the default value when it's off.
2). How to call a function in the Document class from the mouseClick function of the NavButton class, to start building out the rest of the info.
I tried having a textField placed manually on stage with a different name, but still I can't access it from the NavButton class!
My code is attached.
Thank you very much for your help!
-D.
Reference The Document Class From Within Another Class?
OK, I am learning AS3 and I have seen variations of this question asked a thousand times but none seem to do the trick for me...
I have made a document class and some other custom classes that are working nicely. I am having trouble accessing a movieclip instance on the root timeline! (duh) I want _level0 back! I feel like I am being stupid, but i have tried using parent, root, stage, the name of my document class, etc.
It's a guess but the trouble seems to come from the fact that I am linking movieclips in my library to a class, but then physically placing them on the main timeline rather than creating instances via the "new" keyword. I do this out of convenience for design control. Any ideas out there?
thanks for any helps.
Get Class To Run A Function That Is On The Document Class
hey
i'm using a document class called DocClassGraph
and in DocClassGraph i have a function called loadJSON.
then
var graph:GraphClass;
addChild(graph);
and now want to run the function loadJSON from the Graph Class.
i have tryed parent.loadJSON("data2.json");
but this does not work?????
Can't Instantiate A Class From Within My Document Class
My classes work when I link them to Movie clips, but when I try the below code I get an error:
package {
import flash.display.MovieClip;
import flash.ui.Mouse;
import Enemies;
//
public class VertShooter extends MovieClip {
public var _enemy:Enemies;
//
public function VertShooter () {
trace ("VertShooter Class");
Mouse.hide ();
//
_enemy = new Enemies();
addChild (_enemy);
}
}
}
/////////////////////////
Please help, thanks!
Extending A Class That Is A Document Class Of A Swf/fla
Hey
I have a question about extending or subclassing classes in as3 and flash.
I have a fla project that has its Document Class set to an as3 class called Portrait. B/c the portrait class is a document class of my fla project, it directly accesses all movieclip objects in the scene.
I want to create a new project that extends this project. By that, I mean I would like to extend the functionality by adding more movieclip objects to the scene and more script, but keep the original source code. Is this even possible?
I tried writting a new class called PortraitExt which extends the Portrait class. And I duplicated the original project, added some new objects, and set its document class to PortraitExt. However, when I tried compiling, it complained about the orignal Portrait class not being able to find the movieclip objects that are contained in the scene.
Thanks!
Class Communication Through The Document Class?
Hello all. I've been running into the problem of classes, their variables, and how they are able to interact.
Example:
I have a document class which instantiates two different classes, each with their own public variables. I can call these variables from the document class, but not from one class to the other.
Document class (generic test code)
Code:
var test01:MyClass = new MyClass();
trace(test01.myVar) // outputs: "This is your FIRST test string"
var test02:MyNewClass = new MyNewClass();
trace(test02.myDifferentVar) //outputs: "This is your SECOND test string"
Now say I'm in, "MyClass"
Code:
// here I'm trying to reference an instance of "MyNewClass()" that is in my document class
trace(test02.myDifferentVar) // outputs: undefined
I was under the impression that I would have access to anything in my document class from anywhere in any other class. Is there a way of referencing to the document class, as in its instance name or something?
Code:
// here I'm trying to reference an instance of "MyNewClass()" that is in my document class
trace(*DocumentClass*.test02.myDifferentVar) // outputs: undefined
This is turning out to be a big problem, but I hope there is an easy fix for it. Does anyone have any suggestions?
Thank you,
-EthanG
Document Class
Hiii.
I'm trying the very simple Document class textfield in the Properties dialog box, where I add in the value: Main
I save that as myFlashCS3.fla. There's nothing else in that .fla.
In that same dir, I have Main.as, which has this code:
Code:
package
{
import flash.display.MovieClip;
public class Main extends MovieClip
{
public function Main()
{
trace("holla");
}
}
}
I publish my myFlashCS3.fla and the Output shows nothing. I was expecting it to show: holla
What am I doing wrong?
Thank you.
Document Class
In AS 3.0 using document class can we access MovieClips in frame other than first .... If so how to refer to movieclips in some other frames
More Than 1 Document Class?
Is it possible to attach more than one class to a project in Flash? I have one .as file attached as a document class that extends the movie clip and I want add an alert box class that extends the sprite. How do I go about doing this?
Does anyone know of a tutorial on how to pull xml data and place it in an alert box?
Thanks,
Mike
Help With Document Class
Hi guys, i have 2 swf files, Loader.swf & Shell.swf. They both have a document class each...
Loader.swf's document class "PreLoader"
ActionScript Code:
package com.KB
{
import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.media.*;
import flash.net.*;
import flash.text.*;
import flash.utils.*;
public class PreLoader extends MovieClip
{
public var TEST_TEXT:String;
private var SWF_LOADER:Loader;
private var SWF_PATH:URLRequest;
public function PreLoader()
{
TEST_TEXT = "hello there";
SWF_PATH = new URLRequest("Shell.swf");
SWF_LOADER = new Loader();
SWF_LOADER.contentLoaderInfo.addEventListener(Event.COMPLETE,LOAD_COMPLETE);
SWF_LOADER.load(SWF_PATH);
}
private function LOAD_COMPLETE(e:Event):void
{
trace("load complete");
addChild(SWF_LOADER);
}
}
}
and here's Shell.swf's document class "Shell"
ActionScript Code:
package com.KB
{
import flash.display.*;
import flash.events.*;
import flash.filters.*;
import flash.media.*;
import flash.net.*;
import flash.text.*;
import flash.utils.*;
public class Shell extends MovieClip
{
public function Shell()
{
test();
}
public function test():void
{
try
{
trace(PreLoader(this.parent.parent).TEST_TEXT);
}
catch(err:Error)
{
trace("there was an error");
}
}
}
}
the whole idea is PreLoader loads shell.swf and adds it to the stage and i want to be able to refer a variable or call a function from shell.swf document class to the PreLoader document class. Its easy to do this in a keyframe on the main timeline but using a document class is a little different, help please!
Document Class
Hi,
I just started with AS3. I've made some simple tests and everything is working fine. Now what my question is about, I've made my Document class called Main.as In that class i've imported a subclass of me. Now is there any way to access a movieclip on my stage in my subclass?
Thanks in advance...
Document Class
Actionscript 3/Flash 9 introduces the Document Class. I think I understand the concept that it enables you to link an external .as file which then acts as if it is the _root class. Firstly, is that correct? Secondly, given that you can create code in external .as files in ActionScript 2, what's the practical advantage of this new features over AS2?
Kev
Specifying A Document Class
I just started read the book "Foundation Action Script 3.0" and i got to "Specifying a document class". I create a document.fla and enter a Document class called : Document.
I then create a Document.as and i write:
package {
import flash.display.MovieClip;
public class Document extends MovieClip {
public function Document () {
trace("Hello World");
}
}
}
Bit i get a 5007 error in Line1? Can anyone help :-)
But when i Test Movie I get a 5007 error
Help With Document Class
heres my code
Code:
package{
import flash.display.Sprite;
import flash.display.MovieClip;
public class Tools extends Sprite{
public function Tools()
{
}
var window1:MovieClip = new MovieClip();window1.width=950;window1.height=150;addChild(window1);
var window2:MovieClip = new MovieClip();window2.width=950;window2.height=150;addChild(window2);
var window3:MovieClip = new MovieClip();window3.width=950;window3.height=150;addChild(window3);
var window4:MovieClip = new MovieClip();window4.width=950;window4.height=150;addChild(window4);
}
}
my problem is it gives me undefined property calls, the var definition for the movieclips are ok but after that it doesnt recognize the var for giving it a property and it gives an error, i also get an error in addChild as an undefined method, help would be very greatful plx
Document Class Question
What's the difference between having a class be the 'Document Class' and just importing it on frame 1 in the timeline?
How Do I Avoid Using The 'Document Class'?
Hey all,
I've made a game in as3. I have one main .as file that runs the game. That .as file loads all the graphics, creates other classes, etc.
To instantiate the main class, I just added it to the 'Document Class' option in CS3 (if you start a new project and click on the stage and then go to properties, it allows you to add a document class. Now I assume that when the swf file is run, it automatically instantiates the class and then the game goes from there.
My question is this : How do I not use the document class option? I'd like to instantiate the class myself.
For example, on frame 1 of the swf file, I tried somethign liek this which didn't work :
Code:
import MainGameClass
var foo:MainGameClass = new MainGameClass();
The code ran perfect before when I used the document class option. Now by changing it to the code above I get tons of errors (50+).
Every error reported is like :
1120: Access of undefined property timeleftTextField.
1123: Access of undefined property livesleftTextField.
etc...
What do I need to do to make this work? I assume this is because my MainGameClass is not at the same level as before....
Thanks in advance for taking the time to help me!
Ryan Ritten
Question On Document Class
I'm still getting my feet wet with Actionscript 3, so please forgive any stupidity here :b.
I'm still currently coding some of my work in the timeline because I haven't fully mastered the language yet, so here's my question:
I would like to make a document class and put the following code in it to resize my content on every new frame instead of inserting the code into my timeline on every new frame that needs to be repositioned.
Code:
this.stage.addEventListener(Event.RESIZE, resizeHandler);
function resizeHandler(event:Event):void {
position();
}
position();
function position() {
example.x = stage.stageWidth/2;
example.y = stage.stageHeight/2;
}
I've tried a few attempts at making a document class but just get errors galore. This seems like it would be rather simple but I'm just not seeing the obvious.
Can anyone help me sort a solution out?
Preloader & Document Class
Hi.
When I start a Flash Project, I usually write the Document Class and link it to the .FLA. It obviously works and I think it's the best way to do everything.
The problem is ... How to implement a preloader?
The most obvious answer is: move everything is on the first frame to the (for example) 15th one. Then make the classic "looping code" (that shows the progress bar or the bytes loaded etc.) directly on the frames.
But the Document Class is loaded on the 1st frame and every target called by the Document Class stays on the 15th frame!
So I ask you: What technique do you use to make live together a Document Class based project and a preloader?
Thank you.
Document Class Confusion
Hey new to flash so please forgive my ignorance, but I have a image gallery I built using the document class and xml and I want to know how to add it to the stage via a button. I have a fla file I'm working on and I want the gallery to appear when the gallery button is clicked and to disappear when another button is pushed. I know I have to import the class but what after that? Thanks.
I'm Stuck On Document Class
I have a preloader on frame 1 of the timeline.
this.addEventListener(Event.ENTER_FRAME, loading);
function loading(event:Event):void {
var total:Number = this.stage.loaderInfo.bytesTotal;
var loaded:Number = this.stage.loaderInfo.bytesLoaded;
if (total == loaded) {
gotoAndPlay("start");
this.removeEventListener(Event.ENTER_FRAME, loading);
}
}
stop();
I also have an example of a document class which I found on the forum from cancerinform(moderator).
package {
import flash.display.MovieClip;
public class classRoot extends MovieClip {
public function classRoot() {
}
}
}
When I test the movie I get this message:
Discription
1046: Type was not found or was not a compile-time constant: Event.
Source
function loading(event:Event):void {
If I take the document class away then the swf plays fine.
I just need to understand why this is happening.
Preloader And Document Class
Hi,
I have a fla associated with a Document Class and I can't get a preloader to load function properly in terms of intializing the .as class--
This is the error I get:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MyContentNew2/init()
at MyContentNew2()
I tried two different methods--One with a separate fla entitled preloader with this code:
Code:
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop);
l.contentLoaderInfo.addEventListener(Event.COMPLETE, done);
l.load(new URLRequest("finished4experiment.swf"));
function loop(e:ProgressEvent):void
{
var perc:Number = e.bytesLoaded / e.bytesTotal;
percent.text = Math.ceil(perc*100).toString();
}
function done(e:Event):void
{
removeChildAt(0);
percent = null;
addChild(l);
}
This doesnt seem to work at all---The other method I tried was to put the preloader code within my fla file by adding an additional scene which I put prior to the main movie---Heres the code for that:
Code:
stop();
var finished:Boolean = false;
addEventListener(Event.ENTER_FRAME, loader);
function loader(event:Event) {
var total = stage.loaderInfo.bytesTotal;
var loaded = stage.loaderInfo.bytesLoaded;
var percentage = Math.round(100*loaded/total);
myPreloader.bar.width = 4*percentage
myPreloader.loadingtext.text = "Loading: "+String(percentage)+"%";
if (loaded >= total&&finished==false) {
setTimeout(end_preload,2000);
finished = true;
}
}
function end_preload():void{
removeChild(myPreloader);
gotoAndStop(2);
removeEventListener(Event.ENTER_FRAME,loader);
}
This one kind of works but throws the same error and its obvious that the init function of the main document class isnt being initialized as the variables I've assigned there which control image scale etc arent scaling etc.
Does anyone know why the preloader would result in the main document class not being initialized?
Thanks,
----Yvette
Extending The Document Class
I've build a flash FLA project which has the class "MyGame" as its document class which all works great.
Now I want to make a slightly different version of it with a few bits of extra functionality, so I've got a new FLA, and want it to use an extended version of MyGame as its document class, let's say it's called "MySlightlyDifferentGame".
So the code for MySlightlyDifferentGame looks like this...
code:
package {
import flash.display.*;
public class MySlightlyDifferentGame extends MyGame {
public function MySlightlyDifferentGame(){
super();
// stuff here...
}
}
}
Trouble is, MyGame is now not recognising any objects on the stage of the FLA any more (they're all in the same place as they were in the original).
So for example I have a button on the first frame called "play_btn", and when myGame tries to reference it, I get:
1120: Access of undefined property play_btn.
Any ideas???
How Do You Refer To The Document Class?
I know that this must be an elementary problem, but I'm wondering how to refer to the Document Class that is instantiated by Flash?
I create a Flash AS3.0 project and create a class called "Main". I then edit the Publish settings and set the Document Class to be "Main".
Now how do I refer to the functions in this Main class?
Any help would be greatly appreciated!
Should I Have A Document Class If I Am Using Classes?
i am not sure what the advantages are of assigning a document class. i know that i don't have to import classes to the main timeline if i already imported my classes into the document class, but other than that i have no clue. i also wonder if assigning a document class adds another step to some of the code i may use, or makes it more complex/more likely to fail.
Preloader In Document Class
So I understand the idea that the stage has it's own loaderInfo, so that I can use this to listen to the bytes loading..
ActionScript Code:
var bytestotal = stage.loaderInfo.bytesTotal;
var bytesloaded = stage.loaderInfo.bytesLoaded;
but when
ActionScript Code:
if (bytesloaded >= bytestotal) {
how do i get it to continue on?.. usually you'd use gotoandplay frame 2 or whatever.. but since i'm using a document class, do I need to put everything that was in my constructor into a new function and run that function when "if (bytesloaded >= bytestotal)"
thanks.
Instantiating Document Class
I'm loading an external AS3 swf. It seems that it does not automatically instantiate the Document class. Is this true? How do I explicitly instantiate it?
Help With Document Class Syntax
The following lines of code were on the main timeline and now need to go in a document class .as file...
How do I re-write them properly?
ActionScript Code:
closebutton.addEventListener(MouseEvent.CLICK, unloadFunction);
function unloadFunction(event:MouseEvent) {
dispatchEvent(new Event("UnloadMe", true));
}
Help With Document Class File
I have a newsletter module that allows visitors to register/delete from the database... On its own, it works fine but it is supposed to be loaded externally on the webpage (which is all flash too).
Anytime I click the button to load the newsletter swf module, I get this message:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at Main/init()
at Main()
In this case, Main is the as file that is assigned as document class for the newsletter swf module. I put the code below, and hopefully you guys can help me!
ActionScript Code:
package
{
import flash.display.MovieClip;
import flash.text.TextField;
import flash.utils.Timer;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.events.IEventDispatcher;
import flash.net.URLLoader;
import flash.net.URLVariables;
import flash.net.URLRequest;
import flash.net.URLRequestMethod;
import flash.net.URLLoaderDataFormat;
import flash.events.SecurityErrorEvent;
import flash.events.IOErrorEvent;
public class Main extends MovieClip
{
private var angle:Number=Math.PI/2;
private var timer:Timer;
private var loader:URLLoader;
private const url:String='newsletter.php';
private var _Name:String;
private var _EMail:String;
private var action:String;
public function Main()
{
init();
}
public function init():void
{
stage.frameRate=31;
letter_mc.alpha=.7;
letter_mc.addEventListener(Event.ENTER_FRAME,turnLetter);
email_mc.field_txt.background=name_mc.field_txt.background=true;
email_mc.field_txt.backgroundColor=name_mc.field_txt.backgroundColor=0x999999;
email_mc.field_txt.border=name_mc.field_txt.border=true;
email_mc.field_txt.borderColor=name_mc.field_txt.borderColor=0x0;
join_btn.label='JOIN ME';
join_btn.addEventListener(MouseEvent.MOUSE_DOWN,go);
delete_btn.label='DELETE ME';
delete_btn.addEventListener(MouseEvent.MOUSE_DOWN,go);
}
private function go(evt:MouseEvent):void
{
_EMail=email_mc.field_txt.text;
_Name=name_mc.field_txt.text;
if(EmailChecker.checkEMail(_EMail))
{
if(_Name!="")
{
if(_Name.length>=4)
{
switch(evt.target.name)
{
case 'join_btn':
action='registra';
cool(action);
break;
case 'delete_btn':
action='elimina';
cool(action);
break;
}
}
else
{
notCool('the name is too short');
}
}
else
{
notCool('insert a name');
}
}
else
{
notCool('invaild e-mail address');
}
}
private function turnLetter(evt:Event):void
{
var sine:Number=Math.sin(angle);
var cosine:Number=Math.cos(angle);
evt.target.scaleX=sine;
angle+=.1;
}
private function notCool(s:String):void
{
letter_mc.alpha=.2;
error_txt.text=s;
timer=new Timer(1500,1);
timer.addEventListener(TimerEvent.TIMER,done);
timer.start();
}
private function cool(s:String):void
{
var variables:URLVariables=new URLVariables();
variables.azione=s;
variables.nome=_Name;
variables.eMail=_EMail;
var richiesta:URLRequest=new URLRequest();
richiesta.url=url;
richiesta.method=URLRequestMethod.POST;
richiesta.data=variables;
loader=new URLLoader();
loader.dataFormat=URLLoaderDataFormat.VARIABLES;
addListeners(loader);
try
{
loader.load(richiesta);
}
catch (error:Error)
{
trace('Unable to load requested document.');
}
}
private function done(evt:TimerEvent):void
{
letter_mc.alpha=.7;
error_txt.text="";
}
private function addListeners(d:IEventDispatcher):void
{
d.addEventListener(Event.OPEN,inizio);
d.addEventListener(Event.COMPLETE,completato);
d.addEventListener(SecurityErrorEvent.SECURITY_ERROR,securityError);
d.addEventListener(IOErrorEvent.IO_ERROR,ioError);
}
private function inizio(e:Event):void
{
letter_mc.alpha=.2;
email_mc.visible=false;
name_mc.visible=false;
join_btn.visible=false;
delete_btn.visible=false;
info_mc.visible=false;
}
private function completato(e:Event):void
{
var vars:URLVariables=new URLVariables(e.target.data);
trace(vars.answer);
switch(vars.answer)
{
case 'done':
writeDone();
break;
case 'not done':
writeNotDone();
break;
}
}
private function securityError(e:SecurityErrorEvent):void
{
trace('security error: '+e+'
');
}
private function ioError(e:IOErrorEvent):void
{
trace('send/load error: '+e+'
');
}
private function writeDone():void
{
if(action=='registra')
final_txt.text=' You have been added to our Newsletter.
'+
'A confirmation link has been sentto your e-mail';
else
final_txt.text=' You have been deleted from our Newsletter.
'+
'A confirmation link has been sentto your e-mail';
reset();
}
private function writeNotDone():void
{
if(action=='registra')
final_txt.text=' You already are a member of our Newsletter.
'+
'Enjoy it';
else
final_txt.text=' You are not a member of our Newsletter.
'+
"we can't delete you
"+
'Have a nice day.';
reset();
}
private function reset():void
{
timer=new Timer(4000,1);
timer.addEventListener(TimerEvent.TIMER,resetAll);
timer.start();
}
private function resetAll(evt:TimerEvent):void
{
final_txt.text="";
email_mc.field_txt.text="";
name_mc.field_txt.text="";
letter_mc.alpha=.7;
email_mc.visible=true;
name_mc.visible=true;
join_btn.visible=true;
delete_btn.visible=true;
info_mc.visible=true;
}
}
}
Document Class Gives Errors
Hi,
I've created a document class for my menu.
I am attaching the script for the class.
Then I created a movieclip on the stage and linked it to the class.
When I run my file, I get these errors:
Warning: 1060: Migration issue: The method gotoAndStop is no longer supported. For more information, see MovieClip.gotoAndStop()..
And on the movieclip that is on the stage I get a Red error:
Error #1074: Illegal write to read-only property XML on global.
Any ideas how to fix these errors?
Thank you,
Sigal
Package In Document Class
Hi there
In my main.swf I have a document class called something.as
In this file, there is a package definition.
But strangely when I want to add code in the main.swf, I got a compiled errors:
"1180: Call to a possibly undefined method addFrameScript."
What did I missed ?
|