Use embedded images in FlexLib Project in Actionscript Project - apache-flex

I have a FlexLib Project with a embed class:
package
{
public class EmbedAssets
{
[Embed( source="image.png" )]
public static var IMAGE:Class;
}
}
At the same project, I have a class that use this embedded image:
package
{
import flash.display.DisplayObject;
import flash.display.Sprite;
public class Visual extends Sprite
{
public function Visual()
{
super();
var aa:DisplayObject = new EmbedAssets.IMAGE() as DisplayObject;
addChild( aa );
}
}
}
And I have another Actionscript Project that use this FlexLib Project and add the Visual class on stage:
package
{
import flash.display.Sprite;
public class AsTest extends Sprite
{
public function AsTest()
{
addChild( new Visual());
}
}
}
The image don't show up, just.
I had debug the application and found the bitmapData of aa was NULL. But if I implement out of Lib Project, this work!
In properties of projects ai tried a lot configurations on Flex Library Build Path -> Classes / Assets. But none work correctly.

EDIT: Idemax Green (question author) discovered that it works ok with prev SDK's but not with Flex SDK Hero - Beta - 4.5.0.17689, he logged it as a bug: https://bugs.adobe.com/jira/browse/SDK-29135
If the FlexLib project is merged with your application code, then i'm pretty sure it will not see the image at that location at runtime, as the location will be different e.g. the library will be in the libs folder of the main app. Check where the FlexLib swc is located in you bin-debug folder, and maybe modify the path in EmbedAssets to reflect this.

You should add the library project's assets directory to the application project's source path.
If you are using FlashBuilder, you should edit the flex application's .project file, and extend the linkedResources tag as follows:
<linkedResources>
[...]
<link>
<name>[source path] assets</name>
<type>2</type>
<locationURI>YOUR_WORKSPACE/YourFlexLib/src/assets</locationURI>
</link>
</linkedResources>

Related

Storybook + Vue3 - Error when trying to use custom directives

When trying to use custom directives with Vue3 and storybook, I get this error:
I don't understand the issue and have no idea where to even start to look. I'm still very new to Vue and storybook.
I created a small test directive just to make sure it wasn't something to do with a more complicated one:
app.directive('red-bg', {
beforeMount: (element, binding) => {
element.style.backgroundColor = "red";
}
});
and applied it:
<div class="wmr-select relative" ref="selectRef" v-red-bg>
It works in the normal app part of the the project (as you can see with the red bg):
But in story book I get the error in the first image.
I haven't been able to find any kind of answer for this.
Hoping someone will swoop in and save me.
Thanks.
Since Storybook is using another file to initialize your app, you need to define the directive in both file.
This is explained in the configuring storybook section of the doc.
In my case, I had defined the directive in my main.js file, but I also had to define it in the preview.js file, of the .storybook folder.
As a reference, here is was my .storybook/preview.js looks like:
import { app } from "#storybook/vue3";
/* all the other import needed for my project **/
import store from "#/store";
/** ... */
export const parameters = {
/** Some parameters specifics to the plugins of storybook. **/
/** For example, when using themes. **/
};
/** App specific initialization, ex defining locale */
const i18n = createI18n({
locale: "en",
fallbackLocale: "en",
messages: myLocaleMessageLoader()
});
/** registering directives */
app.directive("my-custom-directive", myCustomDirectiveHandler);
app
.use(i18n)
.use(store)
/** all the other `.use` that my app need.*/
Please note the usage of storybook own app in the import.
After adding the directive in the .storybook/preview.js I was successfully able to use it in my stories.

Extending SilverStripe modules extension

I have installed a particular module in my SilverStripe installation. The following is the directory structure
- Root
- framework
- cms
- mymodule
- code
- extensions
- CustomClass.php
Here is an example of CustomClass.php
class CustomClass extends Extension {
public function init() {
}
public function customMethod() {
}
}
I need to override the customMethod method of the CustomClass class. I could easily change this method, but changing here will cause trouble in the future if the modules get updated. All the changes made will be lost.
So for this I want to extend the extension class used in modules.
I have created an extension /mysite/extensions/MyCustomClass.php
class MyCustomClass extends Extension {
public function customMethod() {
//do my code here
}
}
but I have no idea how to apply this. I thought CustomClass::add_extension("MyCustomClass ") but surely this will not work because add_extension method doesn't exist in CustomClass.
How do we cope with this scenario? Can I use Injector instead? If yes, how can it be called in mysite/_config.php instead of _config.yml?
Using injector does solve the problem but have to use _config.yml as well. Here is what I did.
File /mysite/extensions/MyCustomClass.php
class MyCustomClass extends CustomClass {
public function customMethod() {
//do my code here
}
}
in /mysite/_config/config.yml I added following lines
Injector:
CustomClass:
class: MyCustomClass
And in /mysite/_config.php I added following line
$object = Injector::inst()->create('CustomClass');
And it all worked fine.
There is another way to achieve similar functionality without straight up replacing a previous extension. With SilverStripe's extension system, we can control not only what configuration settings are loaded but the order they are loaded. This is important to note because the customMethod function from an extension, it uses the first one it finds from all the extensions loaded.
Because of this, it can be only a matter of controlling when your MyCustomClass extension is loaded so you can have your own customMethod function run.
Let's say the "MyModule" module has the following YAML file defined:
---
Name: MyModuleExtensions
After:
- 'framework/*'
- 'cms/*'
---
Page:
extensions:
- CustomClass
All we need to do is specify a separate YAML file to run before this "MyModule" one. This can be accomplished like:
---
Name: MyCustomModule
Before:
- MyModule/#MyModuleExtensions
---
Page:
extensions:
- MyCustomClass
Now, when you call your customMethod function on whatever class you have your extensions on (so in my example, the Page class), it will call the one from your MyCustomClass extension.

ResourceManifest SetDependecies doesn't work in Orchard module

I Use Orchard 1.10.1 CMS. I have created a widget module in code. In the ResourceManifest file I added this code
public void BuildManifests(ResourceManifestBuilder builder)
{
var manifest = builder.Add();
manifest.DefineStyle("ShareButtons").SetUrl("ShareButtons.css").SetDependencies("font-awesome.css");
}
and in template cshml I added this code
#{
Style.Require("ShareButtons");
}
Problem is in this case file font-awesome.css won't come in the page's source files.
what am I doing wrong here?
And when I use this code in template it works fine and font-awesome.css will come in the page's source files
#{
Style.Include("font-awesome.css");
Style.Include("ShareButtons.css");
}
ps: In the Style folder of my module project I have ShareButtons.css and font-awesome.css.
Your setup is wrong. You must either register a depency yourself (just like your ShareButton-Style), or in your case use the correct FontAwesome resource from Orchard.Resources.
So your code would look like this:
manifest.DefineStyle("ShareButtons")
.SetUrl("ShareButtons.css")
.SetDependencies("FontAwesome");
Here's the setup of FontAwesome you're requiring as dependency from Orchard.Resources:
namespace Orchard.Resources {
public class FontAwesome : IResourceManifestProvider {
public void BuildManifests(ResourceManifestBuilder builder) {
var manifest = builder.Add();
manifest.DefineStyle("FontAwesome").SetUrl("font-awesome.min.css", "font-awesome.css").SetVersion("4.4.0").SetCdn("//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css", "//maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.css", true);
}
}
}

Meteor 1.3 - lazy loading or evaluation of files

I am very excited with ES2015 modules in Meteor 1.3. We have written an app with medium complexity with Meteor 1.2. As we have very large number of templates and files, it is taking a bit of time to download the content on client side. so I am interested in the lazy loading feature using import. From the meteor night talk, they say that the Blaze templates are still global and cannot be imported (or lazy loaded), I have tried using React inside Blaze.
Added react-template-helper package using meteor add react-template-helper
Create imports folder and added testComponent.jsx file which exports 'TestComponent'
//testComponent.jsx
import React from 'react';
export default class TestComponent extends React.Component {
render() {
return (
<div>
<h1>TestComponent</h1>
<div>This is from Test Component</div>
</div>
);
}
}
After in the Blaze template outside imports folder,
<!-- homeReact template html-->
<template name="homeReact">
<div>
{{> React component=TestComponent}}
</div>
</template>
In the template's js file which is also outside of imports folder
// homeReact template js
import { Template } from 'meteor/templating';
import TestComponent from '/imports/testComponent.jsx`;
Template.homeReact.helpers({
TestComponent() {
return TestComponent;
}
});
This worked but the imports/testComponent.jsx is downloaded on the client (checked using chrome dev tools - sources tab), even if the current route doesn't require homeReact template.
Then I have used require instead of import like this,
// homeReact template js
import { Template } from 'meteor/templating';
Template.homeReact.onCreated(function () {
this.TestComponent = require('/imports/testComponent.jsx').TestComponent;
});
Template.homeReact.helpers({
TestComponent() {
return Template.instance().TestComponent;
}
});
This code also downloads the imports/testComponent.jsx file but in addition I also got an error
In template "homeReact", call to {{> React ... }} missing component argument.
So, my question is, is it possible to lazy load (download) files only when required?

How to minify css in a folder ASP.net

I have CSS files in a folder and I am planning to minify them usign cassette
So far
I have created a class
public class CSSBundleHelper : IConfiguration<BundleCollection>
{
public void Configure(BundleCollection bundles)
{
var BundlePath = ConfigurationManager.AppSettings["CSSBundleFolder"];
var path = ConfigurationManager.AppSettings["CMSSitesPath"];
bundles.AddPerSubDirectory<StylesheetBundle>(path);
}
}
}
What should I pass for the bundle Collection?
List item
Since the CSS files are
in a folder , do I need to pass them using absolute path or a
relative path ?
Since the files are in a folder, i do not have an Idea how to call to this function and do the bundling . I will be happy if someone can guide me
If your css files are in one folder, just pass an application-relative path to bundles.Add(path-to-css-folder)
Then to use this bundle i.e. in Razor: add #Bundles.RenderStyleSheets()

Resources