Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 07-04-2007, 09:24 AM   #1
Pelle
as3 developer
 
Join Date: Jul 2007
Posts: 6
Red face How to declare valid strings for the type argument in e.g. foo(type:String)

Hi!

I noticed that some as3 class methods that uses an argument like 'type:String' also has declared the set of valid strings(constants). How is that done and can I do it or is that only for the adobe guys?

I attached a little picture to show what I mean.

When I implement the call to URLLoader.addEventListener(type:String, ...) flex somehow knows what string constants are valid and gives me a selection
Attached Thumbnails
Click image for larger version

Name:	typedString.PNG
Views:	93
Size:	6.3 KB
ID:	23098  
Pelle is offline   Reply With Quote
Old 07-04-2007, 11:20 AM   #2
panel
AS3
 
panel's Avatar
 
Join Date: Mar 2007
Location: Warsaw
Posts: 1,991
Send a message via Skype™ to panel
Default

It is class with static variables.

ActionScript Code:
package {     public class Direction     {         public static const NEXT:String = "Next";         public static const PREV:String = "Prev";     } }

usage:
ActionScript Code:
myMoveFunction(Direction.NEXT)
panel is offline   Reply With Quote
Old 07-04-2007, 11:47 AM   #3
Pelle
as3 developer
 
Join Date: Jul 2007
Posts: 6
Default

Hi!

Thanx for the reply... but thats not it I'm afraid.

If you look at the Event class it declares a lot of constants but the URLLoader.addEventlistener(type:String, ...) method actually somewhere declares which one of those are valid input.

Have a look in the as3 documentation for the URLLoader class. Scroll down to the table called "Events" (thats the third one). As you can see, those are a subset of a lot of static constants declared in a lot of different classes and among the the Event class.

Whats also interesting is that two of the "valid events" is inherited. Wats also interesting is that the "valid events" is not connected to the method addEventListener(...) since that one also is inherited. It seems to be some sort of declaration on its own... And I want to know how to do that NOW!

As you can see from the attached image, The super class of URLLoader, EventDispatcher has only declared two events.
Attached Thumbnails
Click image for larger version

Name:	typedString.PNG
Views:	96
Size:	4.2 KB
ID:	23100  
Pelle is offline   Reply With Quote
Old 07-04-2007, 11:55 AM   #4
panel
AS3
 
panel's Avatar
 
Join Date: Mar 2007
Location: Warsaw
Posts: 1,991
Send a message via Skype™ to panel
Default

I doubt it's possible. I am guessing it's implemented someware in Flex autocompilation system.
panel is offline   Reply With Quote
Old 07-04-2007, 12:05 PM   #5
Pelle
as3 developer
 
Join Date: Jul 2007
Posts: 6
Default

Nope!

That stuff must have been declared somewhere in those classes. The documentation clearly shows that there is inheritence support. If they could declare it, so could I. Nothing is impossible...

/Pelle
Pelle is offline   Reply With Quote
Old 07-04-2007, 12:19 PM   #6
panel
AS3
 
panel's Avatar
 
Join Date: Mar 2007
Location: Warsaw
Posts: 1,991
Send a message via Skype™ to panel
Default

Quote:
Originally Posted by Pelle View Post
Nope!
That stuff must have been declared somewhere in those classes. The documentation clearly shows that there is inheritence support. If they could declare it, so could I.
/Pelle
Even if you are right those are core classes (written in C++ propably), so it's only for the adobe guys

Quote:
Originally Posted by Pelle View Post
Nope!
Nothing is impossible...
... but somteimes you have spent to mutch time do do something.
panel is offline   Reply With Quote
Old 07-04-2007, 03:40 PM   #7
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

I'm pretty sure those code hints are stored probably in some XML file somewhere in the Flex installation
__________________
(6)
senocular is offline   Reply With Quote
Old 07-05-2007, 06:11 AM   #8
Pelle
as3 developer
 
Join Date: Jul 2007
Posts: 6
Default

Ok...

Would have been neat though...
Pelle is offline   Reply With Quote
Old 07-05-2007, 06:16 AM   #9
icktoofay
Senior Member
 
Join Date: Sep 2006
Posts: 381
Default

If they are XML files though, you can write your own also.
__________________
I am no longer an active ActionScript.org member - sorry!
icktoofay is offline   Reply With Quote
Old 07-05-2007, 02:46 PM   #10
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

You should be able to. I don't know enough about Flex to know how or where they are stored, but I know its XML in Flash and given that Flex is built on Eclipse, I can only imagine something similar is used (then again, its quite possible that they are defined in some Java class but I think that would be dumb). I think there is also some dynamic code hinting going on based on recognized definitions but I don't know how they play together with predefined (the EventDispatcher list seems weird to me)
__________________
(6)
senocular 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 data type of an object at run time J. Grady Broyles ActionScript 2.0 8 01-08-2007 10:06 PM
How to declare a new Data Type? ihtus ActionScript 2.0 2 06-28-2006 08:56 PM


All times are GMT. The time now is 10:20 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.