Yevgeny Simkin
Yevgeny Simkin

Reputation: 28369

How do I get Flash to give me hints on objects that are on the stage?

If I have an element on the stage (let's say a TextField, or a component ComboBox, for example). And I would like, when I reference it in the action script, for the IDE to give me the prompt to show me all the properties associated with that element, how do I create a reference to it, without creating code clutter? I mean, I have a reference to it already on the IDE (the instance name).

So, in the IDE I call it myElement.

Now, if in code I say var myElement:ComboBox; It throws a conflict at compile time. However, if I just reference it as myElement, it has no idea what sort of element it is, so it offers me no help. I know I can say var myCodeElement:ComboBox = myElement as ComboBox, but I really want to avoid that.

What's the correct approach here?

Upvotes: 1

Views: 393

Answers (4)

The_asMan
The_asMan

Reputation: 6402

The IDE will give code hinting only when it knows the type/class of the var.
There are many methods to do this as you can see from the response you got here.
I would do it in 1 of 2 ways depending on if I had an instance already made.
First method is if the instance does not exist

// create a var, type cast it, and use new on it
var tf:TextField = new TextField();
tf. // whenever you type a dot after tf it will trigger the hinting.

Second method is to type cast an already existing instance

(myComboBox as ComboBox). //again typing a "." dot after the ")" will trigger code hinting.

And to combo the 2 methods

var myCombo:ComboBox = (myComboBox as ComboBox)
myCombo // again typing the dot will do it.

Upvotes: 0

Lars Blåsjö
Lars Blåsjö

Reputation: 6127

One approach is to turn of the "Automatically declare stage instances" option and instead declare the instances yourself, in your code.

I'm a bit rusty with regards to the Flash CS IDE, I use Flash Builder nowadays, but if I remember it right, if you name instances on stage and declare public variables with the same name and type, they will be connected. So if you for example have a TextField named myTextField on the stage, you would declare this in code:

public var myTextField:TextField;

You then get the code completion hints while you code, and then when you build and run your swf, the instance on the stage is connected to the variable you declared, so to speak. Or the declared variable reference the instance on stage, whichever way you prefer to look at it.

Upvotes: 0

Yevgeny Simkin
Yevgeny Simkin

Reputation: 28369

Ah! The solution is to wrap the instance name in a constructor of the type that it is, and then proceed as you would otherwise... so...

In my IDE I have a ComboBox component which I have given the instance name of myComboBox.

Later in my code when I wish to address it, rather than just saying myComboBox, I reference it as ComboBox(myComboBox) and the IDE then gives me all the pop up contextual help I need to work with it. I'm not sure if this is causing any extra work behind the scenes, but I think that since I'm not calling new on it, it's just using it in a static way. If anyone has any thoughts on this, I'd love to see them.

Upvotes: 1

Jonatan Hedborg
Jonatan Hedborg

Reputation: 4432

There is an arbitrary naming convention for this iirc; end the instance name with the specified suffix:

_mc = MovieClip

_txt = TextField

etc. They are all defined in a file called ActionsPanel*.xml where they are defined. Something like this:

    <typeinfo pattern="*_mc" object="flash.display.MovieClip"/>
    <typeinfo pattern="*_array" object="Array"/>
    <typeinfo pattern="*_str" object="String"/>
    <typeinfo pattern="*_btn" object="flash.display.SimpleButton"/>
    <typeinfo pattern="*_txt" object="flash.text.TextField"/>
    <typeinfo pattern="*_fmt" object="flash.text.TextFormat"/>
    <typeinfo pattern="*_date" object="Date"/>
    <typeinfo pattern="*_sound" object="flash.media.Sound"/>
    <typeinfo pattern="*_xml" object="XML"/>
    <typeinfo pattern="*_xmlnode" object="flash.xml.XMLNode"/>
    <typeinfo pattern="*_xmlsocket" object="flash.net.XMLSocket"/>
    <typeinfo pattern="*_color" object="fl.motion.Color"/>
    <typeinfo pattern="*_cm" object="flash.ui.ContextMenu"/>
    <typeinfo pattern="*_cmi" object="flash.ui.ContextMenuItem"/>
    <typeinfo pattern="*_pj" object="flash.printing.PrintJob"/>
    <typeinfo pattern="*_err" object="Error"/>
    <typeinfo pattern="*_cam" object="flash.media.Camera"/>
    <typeinfo pattern="*_lc" object="flash.net.LocalConnection"/>
    <typeinfo pattern="*_mic" object="flash.media.Microphone"/>
    <typeinfo pattern="*_nc" object="flash.net.NetConnection"/>
    <typeinfo pattern="*_ns" object="flash.net.NetStream"/>
    <typeinfo pattern="*_so" object="flash.net.SharedObject"/>
    <typeinfo pattern="*_video" object="flash.media.Video"/>

You can probably add in your own definitions there if you dare :)

Upvotes: 0

Related Questions