How definitions should (theoretically) be written in AS3


Note: Once again I am playing around with my purely fictional language beyond the confined bounds of AS3. This post has no practical applications what so ever, and is merely an exercise of the mind.


Java-style definitions
Before explaining my idea, let's take a step back for a second and look at how variables are defined in "Java-like" languages:
Code: public int counter = ; Here you are defining the name counter as an int data type.
You are then merging what should be two lines of code and assigning it a value, but that is a topic for another time.

Now, let's look at how classes are defined:
Code: public class CountingMechanism { } Here you are defining the name CountingMechanism as a class data type.
And theoretically also assigning it immediately after the definition, just without an equals operator.

How class definitions should (theoretically) be written in AS3
Now, if you look at definitions like that and follow the same pattern, theoretically classes should be defined like this:
Code: public var CountingMechanism:Class { } Or, more accurately, since "class"definitions (or rather, named references to those definitions) can't be replaced at runtime, technically they should be constants. Also, according to AS3, constants need to use the assignment operator as well.
Code: public const CountingMechanism:Class = { }
Posted On: Thursday 3rd of January 2013 10:21:46 PM Total Views:  319
View Complete with Replies

RELATED TOPICS OF Flash / ActionScript PROGRAMMING LANGUAGE




coding terms and definitions

all, So im reading through adobes documents and I always run into these seemingly normal terms... (class, method etc...) ... while i understand what their ENGLISH meanings communicate ... Id love to be able to know what they're talking about... does anyone know of a dictionary that has explanations on how such things are used\t
VIEWS ON THIS POST

125

Posted on:

Thursday 25th October 2012
View Replies!

Flex doesn't work the way it should.

I have 3 files. 2 actionscript files and a html file. I want the image to show up at the 0 X coordinate. It shows up at a non-zero position in the browser (firefox 3.*) after I compile everything with flex SDK and run the html file. BUG with flex The embedded png image is 1019 pixels wide. What's going on Attached is a picture of what I see in firefox. package { // first file. import flash.display.Sprite; import flash.display.Bitmap; [SWF(width="1019", height="15")] public class myblackRectangle extends Sprite { [Embed(source="images/mybar.png")] private var rectangleImage:Class; public function myblackRectangle() { var aSprite= new rectangleImage(); addChild(aSprite); } } } package { // Adds the sprite defined in first file as a child to this sprite. import flash.display.Sprite; import myblackRectangle; public class mycanvas extends Sprite { public function mycanvas() { var aSprite = new myblackRectangle(); aSprite.x = 0; // WTFreak is going on //the sprite shows up in //middle of the swf aSprite.y = 0; addChild(aSprite); } } } finally, the basic html embedding stuff.
VIEWS ON THIS POST

114

Posted on:

Thursday 25th October 2012
View Replies!

Low Volume on as3

Hy , I use this function to start the music in my project function tocar() { soundFactory.addEventListener(Event.COMPLETE, completeHandler); soundFactory.addEventListener(IOErrorEvent.IO_ERRO R, ioErrorHandler); soundFactory.addEventListener(ProgressEvent.PROGRE SS, progressHandler); soundFactory.load(request); song = soundFactory.play(); } -------------------------------------------------------------------------- Now i wana low volume of the music. I thought it was something like song.volume = 90; but i was wrong :p Can u help me on this\t
VIEWS ON THIS POST

263

Posted on:

Thursday 25th October 2012
View Replies!

as3 reading and displaying a twitter feed?

So i've been handed a nice little project from my boss. He wants an interactive flash panel that will rotate through several twitter accounts. Anyone have an idea of where i should start. much
VIEWS ON THIS POST

317

Posted on:

Thursday 25th October 2012
View Replies!

website links in as3

This must have been done before and be really easy but I am a newbie so just keep coming up with compiler errors. I have built a website in flash cs4 using as3. I have set up the time line so that each different page on the website exists at a different position on the timeline. Sections have been labeled so that I can jump to that section upon button click. What happens is when the link to the page/section is clicked the timeline jumps to that section and plays an animation that animates the page onto the stage then stops.("in animation") When you click another link the page should animate off of the stage ("out animation")and the next one animates in. (I have set the time line up so that after each "in" animation there is a stop and after each "out" animation there is a stop.) This is where i'm having the problem. I have set up event listeners for the button clicks But i can only get them to either play the "out" animation then that stops, using this code: Code: home.addEventListener(MouseEvent.CLICK, clickSection); about.addEventListener(MouseEvent.CLICK, clickSection); contact.addEventListener(MouseEvent.CLICK, clickSection); function clickSection(evtObj:MouseEvent) { play(); } or jump to the next section using this code: Code: home.addEventListener(MouseEvent.CLICK, clickSection); about.addEventListener(MouseEvent.CLICK, clickSection); contact.addEventListener(MouseEvent.CLICK, clickSection); function clickSection(evtObj:MouseEvent) { gotoAndPlay(evtObj.target.name); } What i would like to know is how to add the two together so that when a button is clicked the information about what was clicked is added to a variable. The function plays the out animation then when that is complete checks the variable where the page clicked information is then jumps to that section on the timeline and plays it's "in" animation Sorry for the long explanation, but I thought more facts would be better than less Jamie
VIEWS ON THIS POST

336

Posted on:

Thursday 25th October 2012
View Replies!

Need as3 Blur Filter help

how i can initialize the Blur Filter value in as3 pls help
VIEWS ON THIS POST

394

Posted on:

Thursday 25th October 2012
View Replies!

Stacking as3 elements under FLA elements.

Hi. I made a .as Class where some graphical elements are spawned into the stage. However, the Flash (.fla) have some internal graphics that are supposed to be over the graphical elements spawned from the custom class. I tried to make another layer over the layer where the as3 Class is being called, but unfortunately it doesn't do anything, the graphic from the .as still appearing over the internal .fla graphics. How I can make sure the .FLA graphics are appearing over the .as3 graphics (Am I clear)
VIEWS ON THIS POST

253

Posted on:

Thursday 25th October 2012
View Replies!

Bring your big brain here... xml and as3...

Code: var library:XML=; library.book = ; library.book.@bookID = 124; library.book.(@bookID = 124).page.@pageNumber = 1; library.book.(@bookID = 124).page.@pageNumber = 2; library.book.(@bookID = 124).page.@pageNumber = 3; trace(library); // this traces: // // // // // I would like my book to have three pages... anyone with a big brain have some ideas Ps - trying to do it without a loop
VIEWS ON THIS POST

337

Posted on:

Thursday 25th October 2012
View Replies!

passing parameters to function and avoiding duplicate variable definitions

I have shortened this example to keep it simple, otherwise I wouldnt be doint this I need to pass different variables to function inForLoop each time. Code: function someFunction():void { for (var i:int = 0; i < columns; i++) { for (var j:int = 0; j < rows; j++) { inForLoop(i, j);//this is fine } } for (var m:int = 0; m < columns; m++) { for (var n:int = 0; n < rows; n++) { inForLoop(m, n);//ofcourse function inForLoop wouldnt accept this } } for (var p:int = 0; p < columns; p++) { for (var r:int = 0; r < rows; r++) { inForLoop(p, r);//nor this } } } function inForLoop(i:uint, j:uint):void { holder.x = i * IMAGE_PIECE_WIDTH; holder.y = j * IMAGE_PIECE_HEIGHT; } How could I make this work
VIEWS ON THIS POST

129

Posted on:

Thursday 25th October 2012
View Replies!

kaspersky doesn't like as3's url!

Kirupians! [Summary ] I don't know if anybody had already encountred this bug, but, it seems that kaspersky in IE6 doesn't like the opening of popup windows by flash's as3. ExternalInterface.call ("function setWMWindow() {window.open('" + url + "', '" + target + "', '" + features + "');}"); [SYMPTOMS ] i know that many browsers have isues with mouse events used in buttons to triger url opening, that's why i use MouseEvent.CLICK for caling the above code. [MORE INFORMATION ] when i disable kaspersky evrything works fine in all tested browsers; FF, IE.. Thanx for reading!
VIEWS ON THIS POST

357

Posted on:

Thursday 25th October 2012
View Replies!

as3 loader

hello, i just setup this loader i found on the net: Code: var l:Loader = new Loader(); l.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loop); l.contentLoaderInfo.addEventListener(Event.COMPLETE, done); l.load(new URLRequest("world.jpg")); 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); } what i dont understand is that everytime i click the refresh page the loader shows up again(this time loading the image faster) but if the image is already in cache the loader should not show at all (), i would like to achieve a loader that loads the image and after dont come up again everytime.
VIEWS ON THIS POST

334

Posted on:

Thursday 25th October 2012
View Replies!

Simple menu question (I should already know)

, I'm new to the forum, although I've read it a lot. I hope you don't mind answering a newbie question. I have a menu that I want to drop down from the top of the screen. A part is shown, and it drops on mouse over. It works, but it flickers if your mouse is in just the right spot (ie it breaks sometimes). Is this something I should ignore Am I being to anal about it Here are the two versions I have: This is the "corrected" version with timers to prevent the flickering. It doesn't fire on mouse over sometimes, though. So I'm stuck. One way flickers, the other doesn't fire off sometimes. I've ran into this before many times too. Is there a simple solution that I'm missing import fl.transitions.Tween; import fl.transitions.easing.*; //boolean records open/closed state var opened:Boolean = false; menuBG.addEventListener(MouseEvent.MOUSE_OVER, openMenu); menuBG.addEventListener(MouseEvent.MOUSE_OUT, closeMenu); function openMenu(e:MouseEvent):void { if (opened == false) { { new Tween(menuBG, "y", Strong.easeOut, -50, 50, 0.5, true); var myTimer:Timer = new Timer(500, 1); myTimer.addEventListener(TimerEvent.TIMER, timedFunction); myTimer.start(); } } } function timedFunction(e:TimerEvent) { opened = true; } function closeMenu(e:MouseEvent):void { if (opened == true) { new Tween(menuBG, "y", Strong.easeOut, 50, -50, 0.5, true); var myTimer2:Timer = new Timer(500, 1); myTimer2.addEventListener(TimerEvent.TIMER, timedFunction2); myTimer2.start(); } } function timedFunction2 (e:TimerEvent):void { opened = false; } I'm stumped. Usually in this situation I set a speed interval that updates on "enter frame" and stops at a limit, but this is too complex, right
VIEWS ON THIS POST

102

Posted on:

Thursday 25th October 2012
View Replies!

active inactive button state in pure as3 (no mc)

Hi all, I want to create a set of buttons based on loaded images from xml that onClick turn red or grow in size, whatever, Clicking another turns that button red and the old one back to default. Alsoo it will attach a animated movieclip onclick to the button and when pressing another button, it swifts to that button. Code: var tracktype:Array = new Array; var imgArray:Array = new Array; var links:int; var locx:Array = new Array; var locy:Array = new Array; var loc:Array = new Array; var lname:Array = new Array; function showXML(e:Event):void { XML.ignoreWhitespace = true; var sitemap:XML = new XML(e.target.data); links = sitemap.link.length(); var i:int = 0; for (i = 0; i < links; i++) { loc.push(sitemap.link.loc[i].text()); locx.push(sitemap.link.locx[i].text()); locy.push(sitemap.link.locy[i].text()); tracktype.push(sitemap.link.tracktype[i].text()); lname.push(sitemap.link.name[i].text()); if (mapEnabled) { var loader:Loader=new Loader(); loader.contentLoaderInfo.addEventListener(Event.COMPLETE, GenerateSpots); loader.load(new URLRequest("images/hotspots/"+ tracktype[i]+".png")); } } } } function GenerateSpots(event:Event):void { imgArray.push(event.currentTarget.loader); if(imgArray.length==links) { for(var n:int=0;n
VIEWS ON THIS POST

300

Posted on:

Thursday 25th October 2012
View Replies!

Setting up Eclipse for as3 development.

Hiya folks. This is may be a silly question, but bare with me. I am currently using flashdevelop for my "home" work, but to be honest having gotten used to the benefits of eclipse at work i am finding flashdevelop a bit lacking. Mainly the ability to use breakpoints and watch the flash step through process by process and keep track of variables and accessible properties. I basically want to replace flashdevelop with eclipse, (i am not using flex), and i'd like to keep the ability that flashdevelop has to integrate easily with the flash ide (for quick running of the app with ctrl enter, and also for easy integration of the flash ide's library). I am thinking maybe this isn't possible, but i hope it is because it would be an insanely good development environment. Any thoughts
VIEWS ON THIS POST

301

Posted on:

Thursday 25th October 2012
View Replies!

reading iptc metadata with as3

hello. is it possible to read the iptc metadata of a jpeg loaded with as3
VIEWS ON THIS POST

356

Posted on:

Thursday 25th October 2012
View Replies!

[cs4][3d] as3 equivalent of global/local option

Hi! If I change some 3d property via as3, how do set the global/local option usually available under the tools palette Is there a way
VIEWS ON THIS POST

286

Posted on:

Thursday 25th October 2012
View Replies!

as3 Tweening Head-scratcher

Hi . here is a wierd one for you. I cant get my head around it. Im trying to create an animated carosel type thing. I have a main class that loads xml and then external images into a class I called Image which is just really a wrapper for Loader. I have a previous and next buttons that use array methods to move the Image instances around in an array and then sends the correct Image to 3 classes that represent my 3 image positions in my carousel. Heres the important snippet in my main class: Code: private function onPrev(e:MouseEvent):void { _images.unshift(_images.pop()); for (var i:int = 0; i
VIEWS ON THIS POST

238

Posted on:

Thursday 25th October 2012
View Replies!

Flash as3 application Examples

Can you please give me the best sites/examples of as3 application..
VIEWS ON THIS POST

227

Posted on:

Thursday 25th October 2012
View Replies!

as3 physics issue

! The thing is i'm trying to make an effect that emmulates hanging interactive objects so that when the user hits any object it moves according to the mouse position and speed. My problem is that i cant find the way to apply the tension and the "pendulum" kind of movement so it looks natural. any thoughts thanx alot!
VIEWS ON THIS POST

151

Posted on:

Thursday 25th October 2012
View Replies!

[help]as3 xml error

So I'm playing around with xml and as3. Now I got this: Code: var fileList:XMLList = bookInput.Songs.file1; And now I want that if you push a button, file1 changes in file2. So I got this: Code: var j:uint=1; But when I change the first snipped in this: Code: var fileList:XMLList = bookInput.Songs.file+j; it gives this error: TypeError: Error #1034: Type Coercion failed: cannot convert "1" to XMLList. How to fix it
VIEWS ON THIS POST

303

Posted on:

Thursday 25th October 2012
View Replies!

horizontal DD menu with as3

Does anyone have an example of a horizontal drop down menu using AS3
VIEWS ON THIS POST

153

Posted on:

Thursday 25th October 2012
View Replies!

Time to convert, as2 to as3

Apologies if this is the wrong place for my thread. I've happily been using ActionScript 2 for a very long time now, and am very comfortable with it. Whenever I even try to use AS3, the amount of Syntax errors I come across is overwhelming. So I always end up resorting back to AS2. I like to think "if it ain't broke, don't fix it". However, after slowly watching some of the amazing potential AS3 has to offer; I think it's time I move on, and get with the times. So I ask you, are there any handy websites or tutorials you can guide me to, that specifically deal with people trying to wean themselves off AS2 and onto AS3. Distinct things that are now missing from AS2, or common Syntax error resolutions. My AS2 knowledge is good, and all I can find out there for AS3 is either extremely different, or far too advance. I just hope AS3 really isnt that different Thank you.
VIEWS ON THIS POST

115

Posted on:

Thursday 25th October 2012
View Replies!

How can I open a new (_blank) browser window in as3?

Opening a new window in as3 triggers popup blockers on some browsers. How do I get around this problem I need a solution that will work on all browsers and all minor versions of Flash player 9. Like it worked in AS2 with: on(release) { getURL("http://www.adobe.com", "_blank"); } I have done some testing with different ways of opening a new window and with different "wmode"s. But have not found a generic solution that will work on all browsers. To many are blocked by browsers popup blocker. Anyone out there got a solution for me Adobe I have also set up a testpage for checking different browsers. Take a look here: http://kunde.apt.no/paal/ Also check out the results from my testing here (green is OK, red is blocked): http://kunde.apt.no/paal/results.html
VIEWS ON THIS POST

137

Posted on:

Thursday 25th October 2012
View Replies!

dynamic variable names, set() and eval() as2 to as3

hello i've been trying to rewrite this code (it's from flash 8 tutorial) in as3. the problems started with phrasing xml file. here's what i did so far. Code: var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, loadXML); loader.load(new URLRequest("menu_nav.xml")); var ID:Array = new Array; var DisplayName:Array = new Array; var LinkType:Array = new Array; var LinkValue:Array = new Array; var topMenuNum = 0; function loadXML(e:Event):void { var xml:XML = new XML(e.target.data); trace ("the number of total children is... " + xml.children().length()); var i = 0; while ( i < xml.children().length()) { ID.push(xml.children()[i].attributes()[0]); DisplayName.push(xml.children()[i].attributes()[1]); LinkType.push(xml.children()[i].attributes()[2]); LinkValue.push(xml.children()[i].attributes()[3]); if (ID[i] == "TM") { topMenuNum = topMenuNum +1; } i = i +1; } trace ("the total number of top menu items is... " + topMenuNum); } now i have some serious problems with this part (it should be before i=i+1). it's to keep track of how many submenu items there will be. Code: set ("submenu_Finish_" + ID[i] , i); if ( eval(".submenu_Start_" + ID[i]) == undefined ) { set ("submenu_Start_" + ID[i] , i); Total_subs = Total_subs + 1; } set ("Total_Items_in_Submenu_" + ID[i] , eval( "submenu_Finish_" + ID[i]) - eval( "submenu_Start_" + ID[i]) + 1); there was _global in front of every variable. i removed it coz i dont think it would affect the code at this point
VIEWS ON THIS POST

157

Posted on:

Thursday 25th October 2012
View Replies!

need help creating active blur class in as3

hi I came across this awsome class created by pixelfumes called an active blur class. they offer up the source files on there site. the class is written in as2; however, I am trying to convert it to as3 but I am having troubles doing so. can anyone help me. here is a link to an example of what it is I want to acheive. http://www.pixelfumes.com/blog/apr07...BlurClass.html and here is a link to the source files http://pixelfumes.blogspot.com/searchq=active+blur
VIEWS ON THIS POST

163

Posted on:

Thursday 25th October 2012
View Replies!

How do I "include" with as3.0?

I've just jumped from as2 to as3 and it's quite depressing to see I have lots to do to fix everything to work. I have an as file containing loads of functions and commands and I used to link it to the flash file with #include in a frame. That obviously don't work anymore. I tried to search and read about this and find myself puzzled with the class and package. So to replace the include, do I just write the frame: import myPackage.myCode; and wrap my code inside: package myPackage{ public class myCode { code here... } Or how will I do the same thing I used to in as2 I tested the example of the help file. In te as file i wrote: package samples { public class SampleCode { public var sampleGreeting:String; public function sampleFunction() { trace(sampleGreeting + " from sampleFunction()"); } } } and in the main timeline I tried both: import samples.*; import samples.SampleCode; Both gave error: 1172: Definition samples could not be found. 1172: Definition samples:SampleCode could not be found. And I had one component button in the maintimeline (left from previous test) and when testing movie it flickered showing all the buttons states below each other\t\t
VIEWS ON THIS POST

128

Posted on:

Thursday 25th October 2012
View Replies!

this script is working in actionscrip2.0 but this is not wroking in as3

, I working long time in actionscript 2.0. just now i started working in action script 3.0. The script what i have pasted down is working in as2. stop(); click_btn.onPress = function() { gotoAndPlay(1); }; But the same script is not working in as3. I don't know y.please tell me. And also tell what is the differents between actionscript2.0 and actionscript3.0
VIEWS ON THIS POST

233

Posted on:

Thursday 25th October 2012
View Replies!

converting code of countdown to as3

I found the Senocular tutorial to do a contdown in as2, i try to convert, but im starting in action scritp and the code give me a bunch of error, can someone help me. PHP Code: stop();currentDate=newDate();thisYear=currentDate.getFullYear();eventDate=newDate(thisYear,11,25);eventMillisecs=eventDate.getTime();counter.onEnterFrame=function(){currentDate=newDate();currentMillisecs=currentDate.getTime();this.msecs=eventMillisecs-currentMillisecs;if(this.msecs
VIEWS ON THIS POST

258

Posted on:

Thursday 25th October 2012
View Replies!

package folders / should be simple, but not working for me

I'm trying to move on from simple examples to a structured program package, but I can't figure out what I'm doing wrong. I think I've followed the instructions properly: this fla does make a swf w/o compiler problems, but it does not execute the constructor. this example is pretty stripped down. when constructed, devUtil should trace "devUtil constructed". it doesn't. I've tried several different files and folders and working custom classes, all with the same non-results folder structure devBase/src/devPak (devPak contains devUtil.as & devUtil.fla) devUtil.fla doc class = devPak.devUtil devUtil.as code: Code: package devPak { import flash.display.Sprite; public class devUtil extends Sprite { public function devUtil():void { trace("devUtil constructed"); } } } can anyone tell me what am I missing here
VIEWS ON THIS POST

78

Posted on:

Thursday 25th October 2012
View Replies!

as3 faster?? i see the opposite

Made in AS2, 24 fps http://www.patrickjansen.net/test/___as2.html Made in AS3, 24 fps http://www.patrickjansen.net/test/___as3.html The AS2 animation plays faster then the AS3 animation. They're relatively the same in structure, so it boggles me why as2 plays better then as3. weird...
VIEWS ON THIS POST

195

Posted on:

Thursday 25th October 2012
View Replies!

help with php and as3

could someone please explain how to send variables to a php file using actionscript 3 im trying to create a contact form with flash and all the online tutorials i have found use as2. any help would be much appreciated!
VIEWS ON THIS POST

128

Posted on:

Thursday 25th October 2012
View Replies!

[as3] Drawing BitmapData to erase BitmapData

bitmapData.dispose()
VIEWS ON THIS POST

167

Posted on:

Thursday 25th October 2012
View Replies!

Flash Is it possible to use such long parameters in tweening code?

I am using the following code to tween my PortFolio_mc but now I want to add some more parameters to make the content in the center of the page when resizing. How can I modify the code The following is the code I am using: Code: TweenMax.fromTo(PortFolio_mc, 5, {x:980, y:410, alpha:.5}, {x:100, y:410, alpha:1, delay:3, ease:Strong.easeOut}); The following are the detail parameters which I would like to use in WIDTH & HEIGHT of above code: Code: PortFolio_mc.x=stage.stageWidth/2-PortFolio_mc.width/2-180; PortFolio_mc.y=stage.stageHeight/2-PortFolio_mc.height/2; How can I Please help.
VIEWS ON THIS POST

81

Posted on:

Monday 29th October 2012
View Replies!

Flash Oval Crop and Save

i need to create a flash aplication that will be able tu upload an image, crop it in oval form then save it . Because i need to create something similar to jibjab or elfyourself. Do you have any ideea how to do this. maybe just a little part of it to put it together.
VIEWS ON THIS POST

63

Posted on:

Monday 29th October 2012
View Replies!

Flowing background

I'm wondering if any would know how to make a background similar to the attached file
VIEWS ON THIS POST

53

Posted on:

Monday 29th October 2012
View Replies!

my website

i made this to put on my website. its not finished. its just a beta test. the problem is that the videos i put in dont load. they just appear blank. that player i made for it doesnt appearn too. please help!!! here is the test: beta test of my website i know it sucks. please help!!!
VIEWS ON THIS POST

67

Posted on:

Friday 30th November 2012
View Replies!