Weird error when creating new Action Script class - apache-flex

Good Morning,
I have a very odd error working in adobe flexbuilder 3.
Ever since yesterday when ever I create a new class, Flex builder do not see anything wrong in my class.
how do i create one:
Right click on a folder in the package hierarchy
--> new
--> action script class
I leave everthing as is but i give it a name obviously
finish
The class is created.
I can now type anything into this class... Even the words "abc" and flex builder do not see that this is wrong.
if i go to an existing class and type "abs" , the moment i hit save it complains about the "abc"
I have tried the following but the problem still persists.
Deleted my workspace and created a new one and re-import.
If i right click on the class in the Flex navigator the "inlcude class in library" is greyed out.
if anyone can give me an idea, even if it is silly, please do. I really need to be able to add new classes.
thanks
The new class that i have created looks like
package za.co.dcs.cib.das.application.vo.authorisation.appDetails.memberDetails
{
public class MyNewlyTestClass
{
public function MyNewlyTestClass()
{
}
}
}
and then i add "ABC" to it... to which it don't complain about. I can add just about anything i want to this class... and nothing is ever an error.
package za.co.dcs.cib.das.application.vo.authorisation.appDetails.memberDetails
{
public class MyNewlyTestClass
{
public function MyNewlyTestClass()
{
abc
}
}
}
Or if i remove the function
package za.co.dcs.cib.das.application.vo.authorisation.appDetails.memberDetails
{
public class MyNewlyTestClass
{
public MyNewlyTestClass()
{
}
}
}

Flash Builder is plain stupid. The ide does not translate the ActionScript into an abstract syntax tree when typing, only check for the syntax when saving.

Don't know if this is default behavior but what i have found is that...
If I change an existing class the compiler checks the syntax but if I add a random file the compiler will only check the file if that file is used by my application.
I have tried this and it seems to work. The moment that you call that file from within your application it validates and give me errors where should be.
Thanks for all your updates

Related

Storing a view in Xamarin.Forms MvvmCross

I have an app with four main pages, switched through a tab bar (no "back" button).
One page has a lot of content (ScrollView) and takes quite a few seconds until it's rendered. I handle that by showing a "loading" overlay while the work is done. But for that specific page I'd like to keep the view alive, so that when the user switches to another page and comes back later, the page is ready without loading everything again.
I'm not sure how to do that in MvvmCross, though.
I did read the documentation and from what I understood the View Presenter would be the right way to do it, since the docs say:
"Another kind of presentation changes your app can request through
hints includes clearing / modifying the BackStack, changing a root
while maintaining the existent views, … possibilities are really
endless. Once again your app is king here!"
I guess I would need to create a custom MvxPresentationHint for that, but I don't quite get it :(
How or rather where would I access and store/load the View?
I'm generally still quite unfamiliar with MvvmCross (how it works under the hood) and especially customization of Mvx classes, even though I've been using it for a while.
Any explanation and preferably code examples beyond what's written in the documentation would be extremely appreciated!
It isn't meaningful to attempt to "store" a view in MVVM. The XF view is a representation of what will be created with native (e.g. "Android" or "iOS") widgets. Creating and measuring/laying out those native widgets is what is slow. MVVM View Presenter won't speed up that logic.
Instead of "store", you need "keep alive":
For a ContentPage called MyPage, when you create it, store it in a static variable. Then re-use that variable. If you never need more than one of these, you can store it in the class itself.
Modify the "code behind", MyPage.xaml.cs:
public partial class MyPage : ContentPage
{
// Singleton Pattern.
private static MyPage _it;
public static MyPage It {
get {
if (_it == null)
_it = new MyPage();
return _it;
}
}
// "private", because calling this directly defeats the purpose. Instead, use `MyPage.It`.
private MyPage()
{
InitializeComponent();
}
}
To create it, whereever you would put:
new MyPage()
instead put this:
MyPage.It
For instance, you might do PushAsync(MyPage.It);
This will always return the SAME INSTANCE of MyPage. So once it has been created, it keeps its state.
IMPORTANT: Note that the constructor is only called ONCE. Any code that needs to be done each time the page appears, put in override .. OnAppearing() method.
LIMITATION: Views "expect" to be part of the visual hierarchy when they are manipulated. If you attempt to alter the page or its view model while it is not on the screen, you may encounter problems. Those are beyond the scope of this answer - create a new StackOverflow question with the details of any problem you encounter.

Class not available

İ create a project "Deneme". create a folder as "App_Code" and create a class Islem in this folder. Then i create new aspx page but i couldn't see this class.error message is "Deneme is available Deneme is not availabe" I couldn't understand. My friend cab see this class on his computer but I can't. I created a new webform default.aspx. I couldn't reach this class, but I can reach webform1.aspx in this folder.
provide namespace in your Islem.cs like this
namespace Deneme
{
public class Islem
{
// .... logic
}
}
create new class in App_Code folder, there is no namespace by default. so you can no access it.
Troubleshooting when you can't find a class
While working on the project, open the "Object Browser" from the "View" menu. Then in the textbox labeled "Search" type in "Islem" and see what comes up.
If the class doesn't come up at all, you're in the wrong project, or you didn't add the class like you think you did, or it's a different project and you need to add a reference.
If it does come up, take careful note of the class' complete namespace.
My guess
My guess is that you have a mismatch on the namespace. By creating the folder you created a sub-namespace by default, so you probably need to add something like this to the top of your code:
using Deneme.App_Code
or, if you don't want to add that for some reason, you can instantiate an instance of the class using its full name:
var o = new Deneme.App_Code.Islem();
Another guess
Make sure Islem.cs is set to compile. See this answer for instructions.
This is a weird situation but try this. Go to 14 line in your Default.aspx.cs file and press ctrl+.+enter then you will have a new Islem file i the root of your project. Rebuild and then your error will disappear. Then copy the code inside your original Islem to the new generated file. Remove the old Islem and move the new one to App_Code. Hope this help you.

is reading web.config from a class insecure?

i wanted a way of getting settings without having to look them up every time so i made this simple class. ex:
public class CustomConfigSettings
{
public CustomConfigSettings()
{
// Default constructor.
}
public string MySetting
{
get { return ConfigurationManager.AppSettings["mySetting"]; }
}
}
it works fine, but it feels like it might be insecure (for some reason i can't put my finger on). would appreciate feedback on security issues, if any, and any possible alternatives. (webforms; .net 3.5).
This is not insecure by itself. Security depends on who will access your class and if this class permits changes to configurations, then if somebody access your code, he can change settings.
I don't see any reason it would be considered more or less secure to read AppSettings from a class than to read them directly from your code. You're using the proper calls and syntax.
There is no problem with your code.
Anyway you can make the function static, it will look better and do not require creating new instance.

MVVM Light + Blend designer view error: Cannot find resource named 'Locator'.

The application runs fine but i could not see my design in the designer view.
It says Cannot find resource named 'Locator'. Obviously, i did not change anything in the code, i just did the data binding using the data binding dialog...
anyone facing the same problem?
There are two known occurrences where this can happen.
If you change to Blend before you built the application, the DLLs are not available yet and this error can be seen. Building the application solves the issue.
There is a bug in Expression Blend where, if you are placing a user control in another user control (or Window in WPF), and the inner user control uses a global resource, the global resource cannot be found. In that case you will get the error too.
Unfortunately I do not have a workaround for the second point, as it is a Blend bug. I hope we will see a resolution for that soon, but it seems to be still there in Blend 4.
What you can do is
Ignore the error when working on the outer user control. When you work on the inner user control, you should see the design time data fine (not very satisfying I know).
Use the d:DataContext to set the design time data context in Blend temporarily.
Hopefully this helps,
Laurent
I've come up with a reasonably acceptable workaround to this problem since it doesn't appear to have been fixed in Blend 4:
In the constructor for your XAML UserControl just add the resources it needs, provided you're in design mode within Blend. This may be just the Locator, or also Styles and Converters as appropriate.
public partial class OrdersControl : UserControl
{
public OrdersControl()
{
// MUST do this BEFORE InitializeComponent()
if (DesignerProperties.GetIsInDesignMode(this))
{
if (AppDomain.CurrentDomain.BaseDirectory.Contains("Blend 4"))
{
// load styles resources
ResourceDictionary rd = new ResourceDictionary();
rd.Source = new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, "Resources/Styles.xaml"), UriKind.Absolute);
Resources.MergedDictionaries.Add(rd);
// load any other resources this control needs such as Converters
Resources.Add("booleanNOTConverter", new BooleanNOTConverter());
}
}
// initialize component
this.InitializeComponent();
}
There may be some edge cases, but its working OK for me in the simple cases where before I'd get a big red error symbol. I'd LOVE to see suggestions on how to better solve this problem, but this at least allows me to animate user controls that otherwise are appearing as errors.
You could also extract out the creation of resources to App.xaml.cs:
internal static void CreateStaticResourcesForDesigner(Control element)
{
if (AppDomain.CurrentDomain.BaseDirectory.Contains("Blend 4"))
{
// load styles resources
ResourceDictionary rd = new ResourceDictionary();
rd.Source = new Uri(System.IO.Path.Combine(Environment.CurrentDirectory, "Resources/Styles.xaml"), UriKind.Absolute);
element.Resources.MergedDictionaries.Add(rd);
// load any other resources this control needs
element.Resources.Add("booleanNOTConverter", new BooleanNOTConverter());
}
}
and then in the control do this BEFORE InitializeComponent():
// create local resources
if (DesignerProperties.GetIsInDesignMode(this))
{
App.CreateStaticResourcesForDesigner(this);
}
Note: At some point in time this stopped working for me and I ended up hardcoding the path to the Styles.xaml because I got frustrated trying to figure out which directory I was in.
rd.Source = new Uri(#"R:\TFS-PROJECTS\ProjectWPF\Resources\Styles.xaml", UriKind.Absolute);
I'm sure I could find the right path with 5 minutes work, but try this if you're at your wits end like I was!
In MyUserControl.xaml, instead of:
DataContext="{Binding Main, Source={StaticResource Locator}
use:
d:DataContext="{Binding Main, Source={StaticResource Locator}
where "d" has been previously defined as:
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
The reason and workaround explained here
http://blogs.msdn.com/b/unnir/archive/2009/03/31/blend-wpf-and-resource-references.aspx
Look at (b) part of the post.
I had a similar problem with a user control resource.
I added this in my usercontrol xaml code:
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/GinaControls;component/Resources/GinaControlsColors.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
Where GinaControls is the namespace where the control class is declared and /Resources/GinaControlsColors.xaml is the project folder and xaml resource file name.
Hope this helps.
Just add this in your App.xaml.cs at the very beginning
here's my piece of code
[STATThread()]
static void main(){
App.Current.Resources.Add("Locator", new yournamespace.ViewModel.ViewModelLocator());
}
public App(){
main();
}
Make sure the Blend has opened the entire solution and NOT just the single project containing the views. I was right-clicking in Visual Studio and selecting Open In Expression Blend. To my surprize, Blend could not find the solution file, so it only opened the single project.
When I realized this, I launched Blend directly, pointed it to the solution file, and then Blend was able to find the ViewModelLocator in my view.

how to embed pure as3 bitmap assets with flex4 (worked with flex3)

In Flex3, I could compile pure as3 code and use "embed" tags to load in images. This was done by Flex making a BitmapAsset class.
I can still do this in Flex4.
However, there was a trick to fakeout flex3 and use my own mx.core.BitmapAsset class to remove some of the extraneous stuff Flex's BitmapAsset brings in with it. This is described here: http://www.ultrashock.com/forums/flex/embed-flex-assets-without-using-flex-123405.html
Unfortunately, I cannot get these tricks to work with Flex4 and get smaller file sizes. I end up with the error "VerifyError: Error #1014: Class mx.core::BitmapAsset could not be found."
This error leads me to this forum, and a solution as described there: http://tech.groups.yahoo.com/group/flexcoders/message/148762
Following this advice, I add -static-link-runtime-shared-libraries=true, and my swf loads without an error... but this means I am loading in the pieces of the flex framework I wanted to omit (and the file size says so too).
Is there a better way to fake out flex4 when it comes to using Embed?
Will something like work ?
[Embed(source="yourImage.jpg")]
private var ImageC:Class;
private var image = new ImageC();
Keith Peters has a nice article on the subject.
I've created a test project in Flex 4 with [Embed] and fake BitmapAsset.as and can't see the exception:
package
{
import flash.display.Sprite;
public class EmbedTest extends Sprite
{
public function EmbedTest()
{
addChild(new smile());
}
[Embed("smile.png")]
private var smile:Class;
}
}
Try to add -link-report link-report.xml compiler option and check link-report.xml file in bin-debug.
Do you have BitmapAsset.as there? If no, you may have excluded it by externs, external-library-path or load-externs.

Resources