Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 08-06-2008, 12:18 PM   #1
sixtyfootersdude
Member
 
Join Date: May 2008
Location: Halifax, NS, Canada
Posts: 82
Default Default Values for Parameters

Morning,

Little confused why this is giving me a compiler error.

I have class Colors which is all constants:


ActionScript Code:
package{         public class Colors{                 public static const grey:uint = 0xCCCCCC;         public static const blue:uint = 0x2238FF;         public static const darkGrey:uint =0xA2A2A2;         public static const darkBlue:uint = 0x0C0077;         public static const red:uint = 0xFF0000;



Then I have this method in another class and package. (both in the same folder. )

ActionScript Code:
public function drawLine(color:uint=Colors.grey):void{ //line the error is on             connectingLine.graphics.clear();             connectingLine.graphics.lineStyle(1,color);             connectingLine.graphics.moveTo(parrent.comment.xMidpoint(), parrent.post.bottomEdge());             connectingLine.graphics.lineTo(this.comment.xMidpoint(),comment.y-heightOfBar*2);         }


it does not like when I set the default value for the parameter color to Colors.grey. I can set it to zero or 0xCCCCCC (grey) but NOT to Colors.grey. I can use Colors.grey in the body of the method so I know the file is accessable...

Seems strange.

Error:
Code:
1047: Parameter initializer unknown or is not a compile-time constant.

Last edited by sixtyfootersdude; 08-06-2008 at 12:21 PM.
sixtyfootersdude is offline   Reply With Quote
Old 08-06-2008, 12:48 PM   #2
Rhuno
Let's Go Blues!
 
Rhuno's Avatar
 
Join Date: Nov 2007
Location: Orlando, FL
Posts: 252
Send a message via AIM to Rhuno
Default

Are you importing the Colors class at the top of the other file? If the classes are in the same package, you don't need too, but if they are in different packages then you will get that error if it can't find the Colors class.
__________________
Check out my flashblog, yo.
Rhuno is offline   Reply With Quote
Old 08-06-2008, 01:47 PM   #3
Jim Freer
Senior Member
 
Join Date: Jul 2007
Location: Houston, TX
Posts: 355
Send a message via Yahoo to Jim Freer
Default

I've tried your Colors class and used Colors.grey as a default parameter in a constructor of another class and it works. My package declaration is blank throughout so Rhuno's post may be the key.
Jim Freer is offline   Reply With Quote
Old 08-06-2008, 01:58 PM   #4
sixtyfootersdude
Member
 
Join Date: May 2008
Location: Halifax, NS, Canada
Posts: 82
Default

Hmmm thanks, Jim and Rhuno.

Using a work around now. Rhuno, I am alittle confused about importing classes. It is my understanding that I do not need to import them if they are in the same folder.

Secondly I did not think that you were allowed to have more than one class in a package.

Lets say that I have Folder:

Jake's harddrive
General Flash Programs (folder)
ArrayTools.as
Colors.as
Comment Project (folder)
MyWork.fla
drawStuff.as

and I want draw stuff to use Colors. What would my import look like to et colors into draw stuff?

thanks again
sixtyfootersdude is offline   Reply With Quote
Old 08-06-2008, 02:49 PM   #5
Jim Freer
Senior Member
 
Join Date: Jul 2007
Location: Houston, TX
Posts: 355
Send a message via Yahoo to Jim Freer
Default

I don't want to confuse you. I don't use Flash and I don't like to use libraries shared between projects which is contrary to just about everyone. I develop alone. I don't want to build dependencies between projects. So hopefully someone will jump in with a good explanation.

In the meantime, I can say the purpose of packages is to put classes together because they have some sort of relationship. Frequently, this is because they are dependent on each other. However, looking at the way Flash's packages are assembled you might also assume classes are packaged together because their usage is similar. They don't try to subdivide too much (thankfully).

I think you can say packages are folders. (I'm only saying this because I'm hoping for an expert to step in and challenge me and offer a better explanation.)
Jim Freer is offline   Reply With Quote
Old 08-06-2008, 03:53 PM   #6
QuantumTiger
Member
 
QuantumTiger's Avatar
 
Join Date: Jul 2008
Location: London
Posts: 69
Default

There is some little piece of OOP subtlety going on here. You don't need to import the packaged to create an instance of the class it contains - but you do need to import the package to access the base class and the static variables contained within it. Someone cleverer than me will have to explain why that should be

http://livedocs.adobe.com/flex/2/doc...=00001841.html

ActionScript Code:
import Colors;
Should do the trick.
__________________
QT
Shadowfax on ActionScipt
QuantumTiger is offline   Reply With Quote
Old 08-06-2008, 04:19 PM   #7
Jim Freer
Senior Member
 
Join Date: Jul 2007
Location: Houston, TX
Posts: 355
Send a message via Yahoo to Jim Freer
Default

That's interesting, QuantumTiger. Hopefully they'll include why it works without importing in my case where I have a simple application with 3 classes and leave the package declarations in all 3 empty.

I am using FlashDevelop and the compile options may make the difference.

Last edited by Jim Freer; 08-06-2008 at 04:21 PM. Reason: 2nd paragraph
Jim Freer is offline   Reply With Quote
Old 08-06-2008, 04:44 PM   #8
senocular
six eyes
 
senocular's Avatar
 
Join Date: Jan 2003
Location: San Francisco, CA (USA)
Posts: 7,875
Send a message via ICQ to senocular Send a message via AIM to senocular Send a message via MSN to senocular Send a message via Yahoo to senocular
Default

import Colors; is redundant. You don't need to use import unless you're using a class that's in a package. In fact it does nothing. The only time you might want to include something like that is to explicitly indicate a dependancy in source code.

The simple fact of this issue is that values outside the scope of the current class cannot be used as default parameters (to my knowledge, and Jim, I'd be interested to see what worked for you). You would either have to explicitly include the value using it's literal or use a constant within that class's definition. Constant's within a class's own definition can be recognized and used.
__________________
(6)
senocular is offline   Reply With Quote
Old 08-06-2008, 04:51 PM   #9
pj-co
Site Contributor
 
pj-co's Avatar
 
Join Date: Jun 2008
Location: Brooklyn
Posts: 360
Default

I think techically, importing a class is "opening up the scope" of that class to be available to Actionscript. It may be that somehow the default folder/unnamed packages are technically opened already but I am surprised that works without imports. Interesting quirk though.
pj-co is offline   Reply With Quote
Old 08-06-2008, 04:55 PM   #10
QuantumTiger
Member
 
QuantumTiger's Avatar
 
Join Date: Jul 2008
Location: London
Posts: 69
Default

Quote:
Originally Posted by Jim Freer View Post
That's interesting, QuantumTiger.
Sadly not. I should have stuck by my motto "When you find something interesting it invariably means you've made a mistake". I had a whole load of error 1047's the other day which I thought I'd solved with a well-placed import statement - but now I comment the import out and it still works. So apologies (sheepish grin!)...
__________________
QT
Shadowfax on ActionScipt
QuantumTiger is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting Default Values in Ctor sixtyfootersdude ActionScript 3.0 2 07-31-2008 04:19 PM
Components, properties and default values rubix222 Components 0 04-16-2008 02:54 PM
Default Argument Values plutocrat ActionScript 3.0 1 06-01-2007 05:15 PM
Inspectable Objects Default Values matthewwithanm Components 0 05-05-2006 09:27 PM
[inspectable] and default values for arrays? toddclare Components 0 05-23-2005 07:16 PM


All times are GMT. The time now is 03:45 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.